Commit 9e66649

mo khan <mo@mokhan.ca>
2016-05-01 23:44:33
add capybara spec for loading gyms.
1 parent 115dfe3
Changed files (4)
app
spec
features
support
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
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>
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
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