aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/routes_spec.rb
blob: 3bd2071d26cc8b9e7e67d8f66bae00725c718fc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
describe "Routes", :type => :feature do
  login_user

  let(:line) { create :line }
  let!(:route) { create(:route, :line => line) }
  let!(:route2) { create(:route, :line => line) }
  #let!(:stop_areas) { Array.new(4) { create(:stop_area) } }
  let!(:stop_points) { Array.new(4) { create(:stop_point, :route => route) } }
  let!(:journey_pattern) { create(:journey_pattern, route: route) }

  before { @user.update(organisation: referential.organisation) }

  with_permissions "boiv:read" do
    it "line page displays line's routes" do
      visit referential_line_path(referential, line)
      expect(page).to have_content(route.name)
      expect(page).to have_content(route2.name)
    end

    describe "from line's page to route's page" do
      it "display route properties" do
        visit referential_line_path(referential, line)
        click_link "#{route.name}"
        expect(page).to have_content(route.name)
        expect(page).to have_content(route.number)
      end
    end

    describe "from line's page, create a new route" do
      it "return to line's page that display new route" do
        visit referential_line_path(referential, line)
        click_link "Ajouter un itinéraire"
        fill_in "route_name", :with => "A to B"
        fill_in "route_published_name", :with => "Published A to B"
        # select 'Aller', :from => "route_direction"
        check('route[wayback]')
        click_button("Valider")
        expect(page).to have_content("A to B")
        expect(page).to have_content("Published A to B")

      end
    end

    describe "Modifies boarding/alighting properties on route stops" do
      xit "Puts (http) an update request" do
        #visit edit_boarding_alighting_referential_line_route_path(referential, line, route)
        visit referential_line_route_path(referential, line, route)

        click_link I18n.t('routes.actions.edit_boarding_alighting')
        #select('', :from => '')
        # Changes the boarding of the first stop
        # Changes the alighting of the last stop
        # save
        #click_button(I18n.t('helpers.submit.update', model: I18n.t('activerecord.models.route.one')))
        click_button(I18n.t('helpers.submit.update', model: I18n.t('activerecord.models.route.one')))
      end
    end

    describe 'show' do
      before(:each) { visit referential_line_route_path(referential, line, route) }

      context 'user has permission to edit journey patterns' do
        skip "not sure the spec is correct or the code" do
          it 'shows edit links for journey patterns' do
            expect(page).to have_link(I18n.t('actions.edit'), href: edit_referential_line_route_journey_pattern_path(referential, line, route, journey_pattern))
          end
        end
      end

      context 'user does not have permission to edit journey patterns' do
        it 'does not show edit links for journey patterns' do
          @user.update_attribute(:permissions, [])
          visit referential_line_route_path(referential, line, route)
          expect(page).not_to have_link(I18n.t('actions.edit'), href: edit_referential_line_route_journey_pattern_path(referential, line, route, journey_pattern))
        end
      end

      context 'user has permission to destroy journey patterns' do
        it 'shows destroy links for journey patterns' do
          expect(page).to have_content(I18n.t('actions.destroy'))
        end
      end

      context 'user does not have permission to destroy journey patterns' do
        it 'does not show destroy links for journey patterns' do
          @user.update_attribute(:permissions, [])
          visit referential_line_route_path(referential, line, route)
          expect(page).not_to have_link(I18n.t('actions.destroy'), href: referential_line_route_journey_pattern_path(referential, line, route, journey_pattern))
        end
      end
    end

    describe 'referential line show' do
      before(:each) { visit referential_line_path(referential, line) }

      context 'user has permission to edit routes' do
        it 'shows edit buttons for routes' do
          expect(page).to have_content(I18n.t('actions.edit'))
        end
      end

      context 'user does not have permission to edit routes' do
        it 'does not show edit buttons for routes' do
          @user.update_attribute(:permissions, [])
          visit referential_line_path(referential, line)
          expect(page).not_to have_link(I18n.t('actions.edit'), href: edit_referential_line_route_path(referential, line, route))
        end
      end

      context 'user has permission to create routes' do
        it 'shows link to a create route page' do
          expect(page).to have_content(I18n.t('routes.actions.new'))
        end
      end

      context 'user belongs to another organisation' do
        xit 'does not show link to a create route page' do
          expect(page).not_to have_content(I18n.t('routes.actions.new'))
        end
      end

      context 'user does not have permission to create routes' do
        it 'does not show link to a create route page' do
          @user.update_attribute(:permissions, [])
          visit referential_line_path(referential, line)
          expect(page).not_to have_content(I18n.t('routes.actions.new'))
        end
      end

      context 'user does not have permission to destroy routes' do
        it 'does not show destroy buttons for routes' do
          @user.update_attribute(:permissions, [])
          visit referential_line_path(referential, line)
          expect(page).not_to have_link(I18n.t('actions.destroy'), href: referential_line_route_path(referential, line, route))
        end
      end
    end
  end
end