Skip to content

Commit

Permalink
Add city to groups
Browse files Browse the repository at this point in the history
  • Loading branch information
lujanfernaud committed Apr 4, 2018
1 parent 1612ed4 commit 0ce568f
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
78 changes: 39 additions & 39 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions app/views/groups/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
required: true %>
</div>

<div class="form-group">
<%= f.label :city %>
<small class="text-muted">Required *</small>
<%= f.text_field :city, required: true, class: "form-control" %>
</div>

<div class="form-group mb-0">
<%= f.label :description %>
<small class="text-muted">Required *</small>
Expand Down
9 changes: 9 additions & 0 deletions app/views/groups/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
<div class="col-md-4">
<div class="box group-info-box p-3">

<div class="group-location">
<h3 class="h4 mb-3">
City
</h3>
<p>
<%= @group.city %>
</p>
</div>

<div class="organizers-preview">
<h3 class="h4 mb-3">
<%= organizer_title %>
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20180404064557_add_location_to_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddLocationToGroups < ActiveRecord::Migration[5.1]
def change
add_column :groups, :location, :string
add_index :groups, :location
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameLocationToCityInGroups < ActiveRecord::Migration[5.1]
def change
rename_column :groups, :location, :city
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
23 changes: 13 additions & 10 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/controllers/groups_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

one:
name: Nike
city: Portland, Oregon
description: <%= Faker::Lorem.paragraph %>
image: sample.jpeg
private: true
Expand All @@ -11,6 +12,7 @@ one:

two:
name: Private Group
city: Portland, Oregon
description: <%= Faker::Lorem.paragraph %>
image: sample.jpeg
private: true
Expand All @@ -20,6 +22,7 @@ two:

three:
name: Private & Hidden Group
city: Portland, Oregon
description: <%= Faker::Lorem.paragraph %>
image: sample.jpeg
private: true
Expand All @@ -29,6 +32,7 @@ three:

four:
name: Private & Hidden Group 2
city: Portland, Oregon
description: <%= Faker::Lorem.paragraph %>
image: sample.jpeg
private: true
Expand All @@ -38,6 +42,7 @@ four:

strangers_group:
name: Strangers Group
city: Portland, Oregon
description: <%= Faker::Lorem.paragraph %>
image: sample.jpeg
private: true
Expand All @@ -47,6 +52,7 @@ strangers_group:

public:
name: Public Group
city: Portland, Oregon
description: <%= Faker::Lorem.paragraph %>
image: sample.jpeg
private: false
Expand Down
1 change: 1 addition & 0 deletions test/integration/groups_creation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/integration/groups_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/integration/groups_show_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions test/models/group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0ce568f

Please sign in to comment.