diff --git a/Gemfile b/Gemfile index 23c7bb1..01857cc 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,11 @@ git_source(:github) do |repo_name| "https://github.com/#{repo_name}.git" end +#File uploads rails gem +gem 'carrierwave', '~> 1.0' +#Cloud storage for file uploads, created an account on cloudinary +gem 'cloudinary' + #For different Roles management gem 'rolify' #Authorization gem cancancan for controlling rolify diff --git a/Gemfile.lock b/Gemfile.lock index a480736..210057b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) arel (8.0.0) + aws_cf_signer (0.1.3) bcrypt (3.1.11) bindex (0.5.0) builder (3.2.3) @@ -53,8 +54,15 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + carrierwave (1.2.1) + activemodel (>= 4.0.0) + activesupport (>= 4.0.0) + mime-types (>= 1.16) childprocess (0.8.0) ffi (~> 1.0, >= 1.0.11) + cloudinary (1.8.1) + aws_cf_signer + rest-client coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -71,11 +79,15 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.3) + domain_name (0.5.20170404) + unf (>= 0.0.5, < 1.0.0) erubi (1.7.0) execjs (2.7.0) ffi (1.9.18) globalid (0.4.1) activesupport (>= 4.2.0) + http-cookie (1.0.3) + domain_name (~> 0.5) i18n (0.9.1) concurrent-ruby (~> 1.0) jbuilder (2.7.0) @@ -91,10 +103,14 @@ GEM mail (2.7.0) mini_mime (>= 0.1.1) method_source (0.9.0) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) mini_mime (0.1.4) mini_portile2 (2.3.0) minitest (5.10.3) multi_json (1.12.2) + netrc (0.11.0) nio4r (2.1.0) nokogiri (1.8.1) mini_portile2 (~> 2.3.0) @@ -135,6 +151,10 @@ GEM responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) + rest-client (2.0.2) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) rolify (5.1.0) rspec-core (3.7.0) rspec-support (~> 3.7.0) @@ -191,6 +211,9 @@ GEM thread_safe (~> 0.1) uglifier (3.2.0) execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.4) warden (1.2.7) rack (>= 1.0) web-console (3.5.1) @@ -211,6 +234,8 @@ DEPENDENCIES byebug cancancan (~> 2.0) capybara (~> 2.13) + carrierwave (~> 1.0) + cloudinary coffee-rails (~> 4.2) devise jbuilder (~> 2.5) diff --git a/app/assets/stylesheets/listings.scss b/app/assets/stylesheets/listings.scss index 26576b1..0773f5e 100644 --- a/app/assets/stylesheets/listings.scss +++ b/app/assets/stylesheets/listings.scss @@ -1,3 +1,8 @@ -// Place all the styles related to the Listings controller here. +// Place all the styles related to the listings controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +listing.photo { + width: 10px; + length: 10px; +} diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 154922a..7eb2c71 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,6 @@ class HomeController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_user! def index - + end end diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index a1bd4b4..b655959 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -69,6 +69,6 @@ class ListingsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def listing_params - params.fetch(:listing, {}) + params.require(:listing).permit(:photo, :address, :property_type, :number_of_bedrooms, :number_of_bathrooms, :max_price_per_week, :available_date, :roles) end end diff --git a/app/models/listing.rb b/app/models/listing.rb index c6f31a8..b06447d 100644 --- a/app/models/listing.rb +++ b/app/models/listing.rb @@ -1,2 +1,4 @@ class Listing < ApplicationRecord + mount_uploader :photo, PhotosForListingsUploader + # params.require(:Listing).permit({Photo: []}) end diff --git a/app/uploaders/photos_for_listings_uploader.rb b/app/uploaders/photos_for_listings_uploader.rb new file mode 100644 index 0000000..b261578 --- /dev/null +++ b/app/uploaders/photos_for_listings_uploader.rb @@ -0,0 +1,49 @@ +class PhotosForListingsUploader < CarrierWave::Uploader::Base +# include Cloudinary::CarrierWave + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + # include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url(*args) + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process scale: [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process resize_to_fit: [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + # def extension_whitelist + # %w(jpg jpeg gif png) + # end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index c83a623..691adb5 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,6 +1,4 @@

Home#index

Find me in app/views/home/index.html.erb

Rently front page

- +<%= link_to 'Listings', listings_path %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index bce5d7d..99d812d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -12,6 +12,29 @@

<%= notice %>

<%= alert %>

+ + <% if user_signed_in? %> +
  • + <%= link_to('Logout', destroy_user_session_path, method: :delete) %> +
  • + <% else %> +
  • + <%= link_to('Login', new_user_session_path) %> +
  • + <% end %> + + + + <% if user_signed_in? %> +
  • + <%= link_to('Edit registration', edit_user_registration_path) %> +
  • + <% else %> +
  • + <%= link_to('Register', new_user_registration_path) %> +
  • + <% end %> + <%= yield %> diff --git a/app/views/listings/_form.html.erb b/app/views/listings/_form.html.erb index 63612bf..4d75d16 100644 --- a/app/views/listings/_form.html.erb +++ b/app/views/listings/_form.html.erb @@ -10,6 +10,50 @@ <% end %> +
    + <%= form.label :avatar %> + +
    + +
    + <%= form.label :photo %> + <%= form.file_field :photo %> +
    + +
    + <%= form.label :address %> + <%= form.text_field :address, id: :listing_Address %> +
    + +
    + <%= form.label :property_type %> + <%= form.text_field :property_type, id: :listing_property_type %> +
    + +
    + <%= form.label :number_of_bedrooms %> + <%= form.number_field :number_of_bedrooms, id: :listing_number_of_bedrooms %> +
    + +
    + <%= form.label :number_of_bathrooms %> + <%= form.number_field :number_of_bathrooms, id: :listing_number_of_bathrooms %> +
    + +
    + <%= form.label :max_price_per_week %> + <%= form.number_field :max_price_per_week, id: :listing_max_price_per_week %> +
    + +
    + <%= form.label :available_date %> + <%= form.number_field :available_date, id: :listing_available_date %> +
    + +
    + <%= form.label :roles %> + <%= form.number_field :roles, id: :listing_Roles %> +
    <%= form.submit %> diff --git a/app/views/listings/_listing.json.jbuilder b/app/views/listings/_listing.json.jbuilder index c3128ba..4bcbf1f 100644 --- a/app/views/listings/_listing.json.jbuilder +++ b/app/views/listings/_listing.json.jbuilder @@ -1,2 +1,2 @@ -json.extract! listing, :id, :created_at, :updated_at +json.extract! listing, :id, :Photo, :Address, :property_type, :number_of_bedrooms, :number_of_bathrooms, :max_price_per_week, :available_date, :Roles, :created_at, :updated_at json.url listing_url(listing, format: :json) diff --git a/app/views/listings/index.html.erb b/app/views/listings/index.html.erb index 50f0202..c921e3b 100644 --- a/app/views/listings/index.html.erb +++ b/app/views/listings/index.html.erb @@ -5,6 +5,14 @@ + + + + + + + + @@ -12,6 +20,14 @@ <% @listings.each do |listing| %> + + + + + + + + diff --git a/app/views/listings/show.html.erb b/app/views/listings/show.html.erb index ca12898..2c2c6f8 100644 --- a/app/views/listings/show.html.erb +++ b/app/views/listings/show.html.erb @@ -1,4 +1,44 @@

    <%= notice %>

    +

    + Photo: + <%= @listing.photo %> +

    + +

    + Address: + <%= @listing.address %> +

    + +

    + Property type: + <%= @listing.property_type %> +

    + +

    + Number of bedrooms: + <%= @listing.number_of_bedrooms %> +

    + +

    + Number of bathrooms: + <%= @listing.number_of_bathrooms %> +

    + +

    + Max price per week: + <%= @listing.max_price_per_week %> +

    + +

    + Available date: + <%= @listing.available_date %> +

    + +

    + Roles: + <%= @listing.roles %> +

    + <%= link_to 'Edit', edit_listing_path(@listing) %> | <%= link_to 'Back', listings_path %> diff --git a/config/application.rb b/config/application.rb index c8f96c3..5a23822 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,4 +15,5 @@ module Rently # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. end + require 'carrierwave/orm/activerecord' end diff --git a/config/cloudinary.yml b/config/cloudinary.yml new file mode 100644 index 0000000..9b0eea4 --- /dev/null +++ b/config/cloudinary.yml @@ -0,0 +1,19 @@ +--- +development: + cloud_name: curlyhappiness + api_key: '363646175522825' + api_secret: fGga3bKgIksDm7_vn9uYVFhj2T0 + enhance_image_tag: true + static_image_support: false +production: + cloud_name: curlyhappiness + api_key: '363646175522825' + api_secret: fGga3bKgIksDm7_vn9uYVFhj2T0 + enhance_image_tag: true + static_image_support: true +test: + cloud_name: curlyhappiness + api_key: '363646175522825' + api_secret: fGga3bKgIksDm7_vn9uYVFhj2T0 + enhance_image_tag: true + static_image_support: false diff --git a/config/routes.rb b/config/routes.rb index 4ab179e..ba0e842 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,7 @@ Rails.application.routes.draw do devise_for :users get 'home/index' + root to: "home#index" # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20171103052641_create_listings.rb b/db/migrate/20171103052641_create_listings.rb deleted file mode 100644 index 47cfdb9..0000000 --- a/db/migrate/20171103052641_create_listings.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateListings < ActiveRecord::Migration[5.1] - def change - create_table :listings do |t| - - t.timestamps - end - end -end diff --git a/db/migrate/20171103081805_create_listings.rb b/db/migrate/20171103081805_create_listings.rb new file mode 100644 index 0000000..bcdd9ec --- /dev/null +++ b/db/migrate/20171103081805_create_listings.rb @@ -0,0 +1,16 @@ +class CreateListings < ActiveRecord::Migration[5.1] + def change + create_table :listings do |t| + t.text :photo + t.string :address + t.string :property_type + t.integer :number_of_bedrooms + t.integer :number_of_bathrooms + t.integer :max_price_per_week + t.integer :available_date + t.integer :roles + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b532cff..82c0e7d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,24 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171103035249) do +ActiveRecord::Schema.define(version: 20171103081805) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "listings", force: :cascade do |t| + t.text "photo" + t.string "address" + t.string "property_type" + t.integer "number_of_bedrooms" + t.integer "number_of_bathrooms" + t.integer "max_price_per_week" + t.integer "available_date" + t.integer "roles" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "roles", force: :cascade do |t| t.string "name" t.string "resource_type" diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png deleted file mode 100644 index e69de29..0000000 diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png deleted file mode 100644 index e69de29..0000000 diff --git a/public/uploads/listing/photo/4/Banana-1024x679.jpg b/public/uploads/listing/photo/4/Banana-1024x679.jpg new file mode 100644 index 0000000..cd2c761 Binary files /dev/null and b/public/uploads/listing/photo/4/Banana-1024x679.jpg differ diff --git a/spec/views/listings/edit.html.erb_spec.rb b/spec/views/listings/edit.html.erb_spec.rb index 9a26692..a417351 100644 --- a/spec/views/listings/edit.html.erb_spec.rb +++ b/spec/views/listings/edit.html.erb_spec.rb @@ -2,13 +2,38 @@ require 'rails_helper' RSpec.describe "listings/edit", type: :view do before(:each) do - @listing = assign(:listing, Listing.create!()) + @listing = assign(:listing, Listing.create!( + :Photo => "MyString", + :Address => "MyString", + :property_type => "MyString", + :number_of_bedrooms => 1, + :number_of_bathrooms => 1, + :max_price_per_week => 1, + :available_date => 1, + :Roles => 1 + )) end it "renders the edit listing form" do render assert_select "form[action=?][method=?]", listing_path(@listing), "post" do + + assert_select "input[name=?]", "listing[Photo]" + + assert_select "input[name=?]", "listing[Address]" + + assert_select "input[name=?]", "listing[property_type]" + + assert_select "input[name=?]", "listing[number_of_bedrooms]" + + assert_select "input[name=?]", "listing[number_of_bathrooms]" + + assert_select "input[name=?]", "listing[max_price_per_week]" + + assert_select "input[name=?]", "listing[available_date]" + + assert_select "input[name=?]", "listing[Roles]" end end end diff --git a/spec/views/listings/index.html.erb_spec.rb b/spec/views/listings/index.html.erb_spec.rb index d3612b2..01090df 100644 --- a/spec/views/listings/index.html.erb_spec.rb +++ b/spec/views/listings/index.html.erb_spec.rb @@ -3,12 +3,38 @@ require 'rails_helper' RSpec.describe "listings/index", type: :view do before(:each) do assign(:listings, [ - Listing.create!(), - Listing.create!() + Listing.create!( + :Photo => "Photo", + :Address => "Address", + :property_type => "Property Type", + :number_of_bedrooms => 2, + :number_of_bathrooms => 3, + :max_price_per_week => 4, + :available_date => 5, + :Roles => 6 + ), + Listing.create!( + :Photo => "Photo", + :Address => "Address", + :property_type => "Property Type", + :number_of_bedrooms => 2, + :number_of_bathrooms => 3, + :max_price_per_week => 4, + :available_date => 5, + :Roles => 6 + ) ]) end it "renders a list of listings" do render + assert_select "tr>td", :text => "Photo".to_s, :count => 2 + assert_select "tr>td", :text => "Address".to_s, :count => 2 + assert_select "tr>td", :text => "Property Type".to_s, :count => 2 + assert_select "tr>td", :text => 2.to_s, :count => 2 + assert_select "tr>td", :text => 3.to_s, :count => 2 + assert_select "tr>td", :text => 4.to_s, :count => 2 + assert_select "tr>td", :text => 5.to_s, :count => 2 + assert_select "tr>td", :text => 6.to_s, :count => 2 end end diff --git a/spec/views/listings/new.html.erb_spec.rb b/spec/views/listings/new.html.erb_spec.rb index a3be8b5..dc7f18d 100644 --- a/spec/views/listings/new.html.erb_spec.rb +++ b/spec/views/listings/new.html.erb_spec.rb @@ -2,13 +2,38 @@ require 'rails_helper' RSpec.describe "listings/new", type: :view do before(:each) do - assign(:listing, Listing.new()) + assign(:listing, Listing.new( + :Photo => "MyString", + :Address => "MyString", + :property_type => "MyString", + :number_of_bedrooms => 1, + :number_of_bathrooms => 1, + :max_price_per_week => 1, + :available_date => 1, + :Roles => 1 + )) end it "renders new listing form" do render assert_select "form[action=?][method=?]", listings_path, "post" do + + assert_select "input[name=?]", "listing[Photo]" + + assert_select "input[name=?]", "listing[Address]" + + assert_select "input[name=?]", "listing[property_type]" + + assert_select "input[name=?]", "listing[number_of_bedrooms]" + + assert_select "input[name=?]", "listing[number_of_bathrooms]" + + assert_select "input[name=?]", "listing[max_price_per_week]" + + assert_select "input[name=?]", "listing[available_date]" + + assert_select "input[name=?]", "listing[Roles]" end end end diff --git a/spec/views/listings/show.html.erb_spec.rb b/spec/views/listings/show.html.erb_spec.rb index 0a487e6..1549462 100644 --- a/spec/views/listings/show.html.erb_spec.rb +++ b/spec/views/listings/show.html.erb_spec.rb @@ -2,10 +2,27 @@ require 'rails_helper' RSpec.describe "listings/show", type: :view do before(:each) do - @listing = assign(:listing, Listing.create!()) + @listing = assign(:listing, Listing.create!( + :Photo => "Photo", + :Address => "Address", + :property_type => "Property Type", + :number_of_bedrooms => 2, + :number_of_bathrooms => 3, + :max_price_per_week => 4, + :available_date => 5, + :Roles => 6 + )) end it "renders attributes in

    " do render + expect(rendered).to match(/Photo/) + expect(rendered).to match(/Address/) + expect(rendered).to match(/Property Type/) + expect(rendered).to match(/2/) + expect(rendered).to match(/3/) + expect(rendered).to match(/4/) + expect(rendered).to match(/5/) + expect(rendered).to match(/6/) end end

    PhotoAddressProperty typeNumber of bedroomsNumber of bathroomsMax price per weekAvailable dateRoles
    <%= image_tag listing.photo_url %><%= listing.address %><%= listing.property_type %><%= listing.number_of_bedrooms %><%= listing.number_of_bathrooms %><%= listing.max_price_per_week %><%= listing.available_date %><%= listing.roles %> <%= link_to 'Show', listing %> <%= link_to 'Edit', edit_listing_path(listing) %> <%= link_to 'Destroy', listing, method: :delete, data: { confirm: 'Are you sure?' } %>