Commit e92ce6d
Changed files (2)
spec
features
support
pages
spec/features/gyms_spec.rb
@@ -1,15 +1,16 @@
require 'rails_helper'
feature "Gyms", type: :feature do
+ let(:user_session) { create(:active_session, location: create(:calgary)) }
+
+ before :each do
+ page.set_rack_session(user_id: user_session.id)
+ end
+
feature "viewing gyms" do
subject { GymsPage.new }
let!(:calgary_gym) { create(:gym, name: 'sait', location: create(:calgary)) }
let!(:edmonton_gym) { create(:gym, name: 'nait', location: create(:edmonton)) }
- let(:user_session) { create(:active_session, location: create(:calgary)) }
-
- before :each do
- page.set_rack_session(user_id: user_session.id)
- end
it 'loads the gyms closest to you' do
subject.visit_page
@@ -26,4 +27,30 @@ feature "Gyms", type: :feature do
expect(subject).to have_content(edmonton_gym.name)
end
end
+
+ feature "adding a gym" do
+ subject { NewGymPage.new }
+
+ it 'saves a new gym' do
+ subject.visit_page
+ subject.change(
+ name: 'SAIT',
+ address: '1301 16 Ave NW',
+ city: 'Calgary',
+ region: 'AB',
+ country: 'CA',
+ postal_code: 'T2M 0L4',
+ )
+
+ expect(Gym.count).to eql(1)
+ gym = Gym.last
+ expect(gym.name).to eql('SAIT')
+ expect(gym.location).to be_present
+ expect(gym.location.address).to eql('1301 16 Ave NW')
+ expect(gym.location.city).to eql('Calgary')
+ expect(gym.location.region).to eql('AB')
+ expect(gym.location.country).to eql('CA')
+ expect(gym.location.postal_code).to eql('T2M 0L4')
+ end
+ end
end
spec/support/pages/new_gym_page.rb
@@ -0,0 +1,22 @@
+require_relative "../page_model.rb"
+
+class NewGymPage < PageModel
+ attr_reader :form_id
+
+ def initialize
+ super new_gym_path
+ @form_id = "#new_gym"
+ end
+
+ def change(name:, address:, city:, region:, country:, postal_code:)
+ within form_id do
+ fill_in "gym_name", with: name
+ 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
+ fill_in "gym_location_attributes_postal_code", with: postal_code
+ click_button "Create Gym"
+ end
+ end
+end