From 0ce568f5c462e6262a1a84c444532cd2088b9786 Mon Sep 17 00:00:00 2001 From: lujanfernaud Date: Wed, 4 Apr 2018 16:00:14 +0100 Subject: [PATCH] Add city to groups --- Gemfile | 2 +- Gemfile.lock | 78 +++++++++---------- app/controllers/groups_controller.rb | 2 +- app/models/group.rb | 1 + app/views/groups/_form.html.erb | 6 ++ app/views/groups/show.html.erb | 9 +++ .../20180404064557_add_location_to_groups.rb | 6 ++ ...70556_rename_location_to_city_in_groups.rb | 5 ++ db/schema.rb | 4 +- db/seeds.rb | 23 +++--- test/controllers/groups_controller_test.rb | 1 + test/fixtures/groups.yml | 6 ++ test/integration/groups_creation_test.rb | 1 + test/integration/groups_edit_test.rb | 1 + test/integration/groups_show_test.rb | 1 + test/models/group_test.rb | 6 ++ 16 files changed, 100 insertions(+), 52 deletions(-) create mode 100644 db/migrate/20180404064557_add_location_to_groups.rb create mode 100644 db/migrate/20180404070556_rename_location_to_city_in_groups.rb diff --git a/Gemfile b/Gemfile index e2b87168..405a659d 100644 --- a/Gemfile +++ b/Gemfile @@ -41,7 +41,7 @@ gem 'mini_magick', '4.7.0' gem 'fog', '1.40.0' # Forms country select. -gem 'country_select' +gem 'country_select', '~> 3.1', '>= 3.1.1' # Geolocalization. gem 'geocoder', '~> 1.4', '>= 1.4.5' diff --git a/Gemfile.lock b/Gemfile.lock index 6634c74e..ffbf3aa7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,41 +2,41 @@ GEM remote: https://rubygems.org/ specs: CFPropertyList (2.3.6) - actioncable (5.1.5) - actionpack (= 5.1.5) + actioncable (5.1.6) + actionpack (= 5.1.6) nio4r (~> 2.0) websocket-driver (~> 0.6.1) - actionmailer (5.1.5) - actionpack (= 5.1.5) - actionview (= 5.1.5) - activejob (= 5.1.5) + actionmailer (5.1.6) + actionpack (= 5.1.6) + actionview (= 5.1.6) + activejob (= 5.1.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.5) - actionview (= 5.1.5) - activesupport (= 5.1.5) + actionpack (5.1.6) + actionview (= 5.1.6) + activesupport (= 5.1.6) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.5) - activesupport (= 5.1.5) + actionview (5.1.6) + activesupport (= 5.1.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.5) - activesupport (= 5.1.5) + activejob (5.1.6) + activesupport (= 5.1.6) globalid (>= 0.3.6) - activemodel (5.1.5) - activesupport (= 5.1.5) - activerecord (5.1.5) - activemodel (= 5.1.5) - activesupport (= 5.1.5) + activemodel (5.1.6) + activesupport (= 5.1.6) + activerecord (5.1.6) + activemodel (= 5.1.6) + activesupport (= 5.1.6) arel (~> 8.0) - activesupport (5.1.5) + activesupport (5.1.6) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) addressable (2.5.2) @@ -60,7 +60,7 @@ GEM will_paginate breadcrumbs_on_rails (3.0.1) builder (3.2.3) - byebug (10.0.1) + byebug (10.0.2) capybara (2.18.0) addressable mini_mime (>= 0.1.3) @@ -114,7 +114,7 @@ GEM equalizer (0.0.11) erubi (1.7.1) eventmachine (1.2.5) - excon (0.61.0) + excon (0.62.0) execjs (2.7.0) faker (1.8.7) i18n (>= 0.7) @@ -306,7 +306,7 @@ GEM loofah (2.2.2) crass (~> 1.0.2) nokogiri (>= 1.5.9) - lumberjack (1.0.12) + lumberjack (1.0.13) mail (2.7.0) mini_mime (>= 0.1.1) method_source (0.9.0) @@ -334,7 +334,7 @@ GEM shellany (~> 0.0) orm_adapter (0.5.0) parallel (1.12.1) - parser (2.5.0.4) + parser (2.5.0.5) ast (~> 2.4.0) pg (0.21.0) popper_js (1.12.9) @@ -352,19 +352,19 @@ GEM pundit (1.1.0) activesupport (>= 3.0.0) rack (2.0.4) - rack-test (0.8.3) + rack-test (1.0.0) rack (>= 1.0, < 3) - rails (5.1.5) - actioncable (= 5.1.5) - actionmailer (= 5.1.5) - actionpack (= 5.1.5) - actionview (= 5.1.5) - activejob (= 5.1.5) - activemodel (= 5.1.5) - activerecord (= 5.1.5) - activesupport (= 5.1.5) + rails (5.1.6) + actioncable (= 5.1.6) + actionmailer (= 5.1.6) + actionpack (= 5.1.6) + actionview (= 5.1.6) + activejob (= 5.1.6) + activemodel (= 5.1.6) + activerecord (= 5.1.6) + activesupport (= 5.1.6) bundler (>= 1.3.0) - railties (= 5.1.5) + railties (= 5.1.6) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.2) actionpack (~> 5.x, >= 5.0.1) @@ -380,9 +380,9 @@ GEM ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - railties (5.1.5) - actionpack (= 5.1.5) - activesupport (= 5.1.5) + railties (5.1.6) + actionpack (= 5.1.6) + activesupport (= 5.1.6) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) @@ -496,7 +496,7 @@ DEPENDENCIES capybara-webkit (~> 1.15) carrierwave (= 1.1.0) coffee-rails (~> 4.2) - country_select + country_select (~> 3.1, >= 3.1.1) devise (~> 4.4, >= 4.4.3) faker (~> 1.8, >= 1.8.7) figaro (~> 1.1, >= 1.1.1) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index ce44a2ad..9420ad50 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -65,7 +65,7 @@ def destroy def group_params params.require(:group) .permit( - :name, :description, :image, + :name, :city, :description, :image, :private, :hidden, :all_members_can_create_events ) end diff --git a/app/models/group.rb b/app/models/group.rb index dc10b27e..17484179 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -17,6 +17,7 @@ class Group < ApplicationRecord mount_uploader :image, ImageUploader validates :name, presence: true, length: { minimum: 3 } + validates :city, presence: true, length: { minimum: 3 } validates :description, presence: true, length: { minimum: 70 } validates :image, presence: true diff --git a/app/views/groups/_form.html.erb b/app/views/groups/_form.html.erb index b7b82b89..a7132f9a 100644 --- a/app/views/groups/_form.html.erb +++ b/app/views/groups/_form.html.erb @@ -11,6 +11,12 @@ required: true %> +
+ <%= f.label :city %> + Required * + <%= f.text_field :city, required: true, class: "form-control" %> +
+
<%= f.label :description %> Required * diff --git a/app/views/groups/show.html.erb b/app/views/groups/show.html.erb index 85789e7e..0294afeb 100644 --- a/app/views/groups/show.html.erb +++ b/app/views/groups/show.html.erb @@ -24,6 +24,15 @@
+
+

+ City +

+

+ <%= @group.city %> +

+
+

<%= organizer_title %> diff --git a/db/migrate/20180404064557_add_location_to_groups.rb b/db/migrate/20180404064557_add_location_to_groups.rb new file mode 100644 index 00000000..4e904a6d --- /dev/null +++ b/db/migrate/20180404064557_add_location_to_groups.rb @@ -0,0 +1,6 @@ +class AddLocationToGroups < ActiveRecord::Migration[5.1] + def change + add_column :groups, :location, :string + add_index :groups, :location + end +end diff --git a/db/migrate/20180404070556_rename_location_to_city_in_groups.rb b/db/migrate/20180404070556_rename_location_to_city_in_groups.rb new file mode 100644 index 00000000..5a661e95 --- /dev/null +++ b/db/migrate/20180404070556_rename_location_to_city_in_groups.rb @@ -0,0 +1,5 @@ +class RenameLocationToCityInGroups < ActiveRecord::Migration[5.1] + def change + rename_column :groups, :location, :city + end +end diff --git a/db/schema.rb b/db/schema.rb index f44ce3cd..355f9f54 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180325115034) do +ActiveRecord::Schema.define(version: 20180404070556) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -74,6 +74,8 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.bigint "user_id" + t.string "city" + t.index ["city"], name: "index_groups_on_city" t.index ["user_id"], name: "index_groups_on_user_id" end diff --git a/db/seeds.rb b/db/seeds.rb index f11c6dd6..005e4215 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -43,13 +43,15 @@ def address 27.times do |n| puts "Creating user #{n + 1} of 27" - User.create!(name: Faker::Internet.user_name.capitalize + "#{n}", - email: Faker::Internet.email, - password: "password", + user_name = Faker::Internet.user_name.capitalize + "#{n}" + + User.create!(name: user_name, + email: Faker::Internet.email, + password: "password", password_confirmation: "password", - confirmed_at: Time.zone.now - 1.day, - location: Faker::Address.city, - bio: Faker::BackToTheFuture.quote) + confirmed_at: Time.zone.now - 1.day, + location: Faker::Address.city, + bio: Faker::BackToTheFuture.quote) end @@ -73,11 +75,12 @@ def random_users(number = 5) puts "Creating unhidden group #{index + 1} of 9" user.owned_groups.create!( - name: Faker::Lorem.words(2).join(" "), + name: Faker::Lorem.words(2).join(" "), description: Faker::Lorem.paragraph * 2, - image: File.new("test/fixtures/files/sample.jpeg"), - private: [true, false].sample, - hidden: false, + city: Faker::Address.city, + image: File.new("test/fixtures/files/sample.jpeg"), + private: [true, false].sample, + hidden: false, all_members_can_create_events: false ) end diff --git a/test/controllers/groups_controller_test.rb b/test/controllers/groups_controller_test.rb index 1a2b341a..f517023d 100644 --- a/test/controllers/groups_controller_test.rb +++ b/test/controllers/groups_controller_test.rb @@ -67,6 +67,7 @@ def group_params { name: "Test group", description: Faker::Lorem.paragraph, + city: Faker::Address.city, image: upload_valid_image, private: true, hidden: true, diff --git a/test/fixtures/groups.yml b/test/fixtures/groups.yml index ff529721..2637d23d 100644 --- a/test/fixtures/groups.yml +++ b/test/fixtures/groups.yml @@ -2,6 +2,7 @@ one: name: Nike + city: Portland, Oregon description: <%= Faker::Lorem.paragraph %> image: sample.jpeg private: true @@ -11,6 +12,7 @@ one: two: name: Private Group + city: Portland, Oregon description: <%= Faker::Lorem.paragraph %> image: sample.jpeg private: true @@ -20,6 +22,7 @@ two: three: name: Private & Hidden Group + city: Portland, Oregon description: <%= Faker::Lorem.paragraph %> image: sample.jpeg private: true @@ -29,6 +32,7 @@ three: four: name: Private & Hidden Group 2 + city: Portland, Oregon description: <%= Faker::Lorem.paragraph %> image: sample.jpeg private: true @@ -38,6 +42,7 @@ four: strangers_group: name: Strangers Group + city: Portland, Oregon description: <%= Faker::Lorem.paragraph %> image: sample.jpeg private: true @@ -47,6 +52,7 @@ strangers_group: public: name: Public Group + city: Portland, Oregon description: <%= Faker::Lorem.paragraph %> image: sample.jpeg private: false diff --git a/test/integration/groups_creation_test.rb b/test/integration/groups_creation_test.rb index f1820f93..1b73ad47 100644 --- a/test/integration/groups_creation_test.rb +++ b/test/integration/groups_creation_test.rb @@ -19,6 +19,7 @@ class GroupsCreationTest < ActionDispatch::IntegrationTest end fill_in "Name", with: "Test group" + fill_in "City", with: Faker::Address.city fill_in_description(Faker::Lorem.paragraph) attach_valid_image diff --git a/test/integration/groups_edit_test.rb b/test/integration/groups_edit_test.rb index c5ddd748..2f000d0b 100644 --- a/test/integration/groups_edit_test.rb +++ b/test/integration/groups_edit_test.rb @@ -12,6 +12,7 @@ class GroupsEditTest < ActionDispatch::IntegrationTest visit edit_group_path(group) fill_in "Name", with: "Test group" + fill_in "City", with: Faker::Address.city fill_in_description(Faker::Lorem.paragraph) attach_valid_image diff --git a/test/integration/groups_show_test.rb b/test/integration/groups_show_test.rb index c2d795c7..2a5d5cb1 100644 --- a/test/integration/groups_show_test.rb +++ b/test/integration/groups_show_test.rb @@ -130,6 +130,7 @@ def add_to_members(*users) def assert_group_info_and_image assert page.has_css? ".group-image" assert page.has_content? @group.name + assert page.has_content? @group.city assert page.has_content? @group.description end diff --git a/test/models/group_test.rb b/test/models/group_test.rb index 5449bb27..2df083c2 100644 --- a/test/models/group_test.rb +++ b/test/models/group_test.rb @@ -5,6 +5,11 @@ class GroupTest < ActiveSupport::TestCase assert fake_group.valid? end + test "is invalid without city" do + group = fake_group(city: "") + refute group.valid? + end + test "is invalid without name" do group = fake_group(name: "") refute group.valid? @@ -66,6 +71,7 @@ def fake_group(params = {}) @fake_group ||= Group.new( owner: params[:owner] || users(:phil), name: params[:name] || "Test group", + city: params[:city] || Faker::Address.city, description: params[:description] || Faker::Lorem.paragraph, image: params[:image] || valid_image, private: params[:private] || true,