diff options
| -rw-r--r-- | app/controllers/gyms_controller.rb | 2 | ||||
| -rw-r--r-- | app/views/layouts/application.html.erb | 2 | ||||
| -rw-r--r-- | spec/features/gyms_spec.rb | 29 | ||||
| -rw-r--r-- | spec/support/pages/gyms_page.rb | 7 |
4 files changed, 37 insertions, 3 deletions
diff --git a/app/controllers/gyms_controller.rb b/app/controllers/gyms_controller.rb index f80b2da..7dc190a 100644 --- a/app/controllers/gyms_controller.rb +++ b/app/controllers/gyms_controller.rb @@ -1,6 +1,6 @@ class GymsController < ApplicationController def index - @gyms = Gym.closest_to(current_session.location) + @gyms = Gym.closest_to(current_session.location).includes(:location) end def new diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 12d7679..9c7bc1b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -72,8 +72,6 @@ <ul class="inline-list right"> <li><a href="https://twitter.com/Stronglifters/">Twitter</a></li> <li><a href="https://github.com/stronglifters">Github</a></li> - <li><a href="#">Link 3</a></li> - <li><a href="#">Link 4</a></li> </ul> </div> </div> diff --git a/spec/features/gyms_spec.rb b/spec/features/gyms_spec.rb new file mode 100644 index 0000000..86a80ef --- /dev/null +++ b/spec/features/gyms_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +feature "Gyms", type: :feature do + 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 + expect(subject).to be_on_page + expect(subject).to have_content(calgary_gym.name) + expect(subject).not_to have_content(edmonton_gym.name) + end + + it 'loads all the gyms' do + user_session.location.update_attributes(latitude: 0.0, longitude: 0.0) + subject.visit_page + expect(subject).to be_on_page + expect(subject).to have_content(calgary_gym.name) + expect(subject).to have_content(edmonton_gym.name) + end + end +end diff --git a/spec/support/pages/gyms_page.rb b/spec/support/pages/gyms_page.rb new file mode 100644 index 0000000..3ad0935 --- /dev/null +++ b/spec/support/pages/gyms_page.rb @@ -0,0 +1,7 @@ +require_relative "../page_model.rb" + +class GymsPage < PageModel + def initialize + super gyms_path + end +end |
