Commit 6f13b84

mo khan <mo@mokhan.ca>
2016-05-03 03:08:41
add country selection.
1 parent a984421
Changed files (9)
app/controllers/gyms_controller.rb
@@ -6,6 +6,7 @@ class GymsController < ApplicationController
   def new
     @gym = Gym.new
     @gym.build_location
+    @countries = Carmen::Country.all.map { |x| [x.name, x.code] }
   end
 
   def create
app/views/gyms/new.html.erb
@@ -16,7 +16,7 @@
         <%= location_form.label :region %>
         <%= location_form.text_field :region %>
         <%= location_form.label :country %>
-        <%= location_form.text_field :country %>
+        <%= location_form.select :country, @countries %>
         <%= location_form.label :postal_code %>
         <%= location_form.text_field :postal_code %>
       <% end %>
features/step_definitions/gym_steps.rb
@@ -18,4 +18,3 @@ end
 When /^I choose a city$/ do
   pending
 end
-
spec/controllers/gyms_controller_spec.rb
@@ -26,6 +26,12 @@ describe GymsController do
       expect(assigns(:gym)).to be_instance_of(Gym)
       expect(assigns(:gym).location).to be_present
     end
+
+    it 'loads the available countries' do
+      get :new
+      expect(assigns(:countries).count).to eql(248)
+      expect(assigns(:countries)).to include(["Canada", "CA"])
+    end
   end
 
   describe "#create" do
spec/features/gyms_spec.rb
@@ -38,7 +38,7 @@ feature "Gyms", type: :feature do
         address: '1301 16 Ave NW',
         city: 'Calgary',
         region: 'AB',
-        country: 'CA',
+        country: 'Canada',
         postal_code: 'T2M 0L4',
       )
 
spec/support/pages/new_gym_page.rb
@@ -14,7 +14,7 @@ class NewGymPage < PageModel
       fill_in "gym_location_attributes_address", with: address
       fill_in "gym_location_attributes_city", with: city
       fill_in "gym_location_attributes_region", with: region
-      fill_in "gym_location_attributes_country", with: country
+      select country, from: "gym_location_attributes_country"
       fill_in "gym_location_attributes_postal_code", with: postal_code
       click_button "Create Gym"
     end
spec/factories.rb
@@ -55,6 +55,7 @@ FactoryGirl.define do
   end
   factory :gym do
     name { FFaker::Internet.user_name }
+    association :location
   end
 
   factory :user_session, class: UserSession do
Gemfile
@@ -7,6 +7,7 @@ source 'https://rubygems.org' do
   gem 'capistrano-bundler', '~> 1.1', require: false, group: :development
   gem 'capistrano-rails', group: :development
   gem 'capistrano-rbenv', '~> 2.0', require: false, group: :development
+  gem 'carmen'
   gem 'chartkick'
   gem 'codeclimate-test-reporter', require: nil, group: :test
   gem 'coffee-rails', '~> 4.1'
Gemfile.lock
@@ -83,6 +83,8 @@ GEM
       rack (>= 1.0.0)
       rack-test (>= 0.5.4)
       xpath (~> 2.0)
+    carmen (1.0.2)
+      activesupport (>= 3.0.0)
     chartkick (1.4.2)
     choice (0.2.0)
     cliver (0.3.2)
@@ -414,6 +416,7 @@ DEPENDENCIES
   capistrano-bundler (~> 1.1)!
   capistrano-rails!
   capistrano-rbenv (~> 2.0)!
+  carmen!
   chartkick!
   codeclimate-test-reporter!
   coffee-rails (~> 4.1)!