master
 1require "rails_helper"
 2
 3feature "Gyms", type: :feature do
 4  let(:user_session) { create(:active_session, location: create(:calgary)) }
 5
 6  before :each do
 7    page.set_rack_session(user_id: user_session.id)
 8  end
 9
10  feature "viewing gyms" do
11    subject { GymsPage.new }
12    let!(:calgary_gym) do
13      create(:gym, name: "sait", location: create(:calgary))
14    end
15    let!(:edmonton_gym) do
16      create(:gym, name: "nait", location: create(:edmonton))
17    end
18
19    it "loads all the gyms" do
20      user_session.location.update_attributes(latitude: 0.0, longitude: 0.0)
21      subject.visit_page
22      expect(subject).to be_on_page
23      expect(subject).to have_content(calgary_gym.name)
24      expect(subject).to have_content(edmonton_gym.name)
25    end
26
27    describe "search" do
28      let!(:other_calgary_gym) do
29        create(:gym, name: "world health", location: create(:calgary))
30      end
31
32      it "returns gyms that match the search criteria", js: true do
33        subject.visit_page
34        subject.search("sait")
35
36        expect(subject).to be_on_page
37        expect(subject).to have_content(calgary_gym.name)
38        expect(subject).to have_no_content(other_calgary_gym.name)
39      end
40    end
41  end
42
43  feature "adding a gym" do
44    subject { NewGymPage.new }
45
46    it "saves a new gym" do
47      VCR.use_cassette("geo-location-sait") do
48        subject.visit_page
49        subject.change(
50          name: "SAIT",
51          address: "1301 16 Ave NW",
52          city: "Calgary",
53          region: "AB",
54          country: "Canada",
55          postal_code: "T2M 0L4",
56        )
57
58        expect(Gym.count).to eql(1)
59        gym = Gym.last
60        expect(gym.name).to eql("SAIT")
61        expect(gym.location).to be_present
62        expect(gym.location.address).to eql("1301 16 Ave NW")
63        expect(gym.location.city).to eql("Calgary")
64        expect(gym.location.region).to eql("AB")
65        expect(gym.location.country).to eql("CA")
66        expect(gym.location.postal_code).to eql("T2M 0L4")
67      end
68    end
69  end
70end