Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
change publishing helper order, adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lislis committed Feb 12, 2019
1 parent d0c14ec commit 8f916df
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 58 deletions.
12 changes: 6 additions & 6 deletions app/helpers/walks_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ def walks_public_status_helper(walk)
walk_status = 'walk'
if walk.stations.present? && walk.stations.count >= 2
walk_status = 'station'
if walk.courseline.present?
walk_status = 'courseline'
if walk.stations.first.subjects.present?
walk_status = 'subject'
if walk.stations.first.subjects.first.pages.present?
walk_status = 'page'
if walk.stations.first.subjects.present?
walk_status = 'subject'
if walk.stations.first.subjects.first.pages.present?
walk_status = 'page'
if walk.courseline.present?
walk_status = 'courseline'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/pages/sort.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<span class="pl-2"><%= t 'saving' %>...</span>
</p>
<button id="sortable-save" class="btn btn-secondary"><%= t 'station.save_order' %></button>
<p class="mt-2"><%= link_to t("back"), subject_path(@walk) %></p>
<p class="mt-2"><%= link_to t("back"), subject_path(@subject) %></p>
</div>
</div>
</div>
22 changes: 11 additions & 11 deletions app/views/walks/_public_status.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@
class: "tooltip"%>
</li>

<li class="step-item <%= 'active' if walks_public_status_helper(@walk) == 'courseline' %>">
<% if @walk.stations.count >= 2 %>
<%= link_to t('walk.course.name'), route_walk_path(@walk),
data: { tooltip: t('walk.publish.step_course') },
class: "tooltip"%>
<% else %>
<a disabled="disabled" class="tooltip"
data-tooltip="<%= t('walk.publish.step_course')%>"><%= t('walk.course.name')%></a>
<% end %>
</li>

<li class="step-item <%= 'active' if walks_public_status_helper(@walk) == 'subject' %>">
<% if @walk.stations.first.present? %>
<%= link_to t('subject.singular'), new_station_subject_path(@walk.stations.first),
Expand All @@ -59,6 +48,17 @@
data-tooltip="<%= t('walk.publish.step_page') %>"><%= t('page.singular') %></a>
<% end %>
</li>

<li class="step-item <%= 'active' if walks_public_status_helper(@walk) == 'courseline' %>">
<% if @walk.stations.count >= 2 %>
<%= link_to t('walk.course.name'), route_walk_path(@walk),
data: { tooltip: t('walk.publish.step_course') },
class: "tooltip"%>
<% else %>
<a disabled="disabled" class="tooltip"
data-tooltip="<%= t('walk.publish.step_course')%>"><%= t('walk.course.name')%></a>
<% end %>
</li>
</ul>
</div>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions spec/features/order_stations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
let(:walk) { FactoryBot.create(:walk, user: user) }
let!(:station) { FactoryBot.create(:station, user: user, walk: walk) }

scenario 'cannot find order button' do
scenario 'can find order button' do
sign_in_go_to_walk_page
expect(page).to have_content(station.name)
expect(page).to_not have_css('[data-tooltip="Change order"]')
expect(page).to have_css('[data-tooltip="Change order"]')
end

scenario 'cannot find route button' do
Expand Down
43 changes: 9 additions & 34 deletions spec/features/publish_walk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

within '.walk-publish-container' do
expect(page).to have_selector('.step-item:nth-of-type(2).active')
expect(page).to have_selector('.step-item:nth-of-type(4) a:not([disabled])')
expect(page).to_not have_selector('.step-item:nth-of-type(5) a:not([disabled])')
expect(page).to have_selector('.step-item:nth-of-type(4) a[disabled]')
expect(page).to_not have_selector('.step-item:nth-of-type(5) a[disabled]')
click_link('Route')
end
expect(page).to have_content "Set route"
Expand All @@ -57,16 +57,18 @@
user: user,
walk_id: walk.id,
next: 1) }
let!(:subject) { FactoryBot.create(:subject, user: user,
station: stations.first) }

scenario 'click on subject link', js: true do
sign_in user
visit "/en/walks/#{walk.id}"
expect(page).to have_content "You cannot publish your walk right now."

within '.walk-publish-container' do
expect(page).to have_selector('.step-item:nth-of-type(3).active')
expect(page).to have_selector('.step-item:nth-of-type(3) a:not([disabled])')
expect(page).to have_selector('.step-item:nth-of-type(4) a:not([disabled])')
expect(page).to_not have_selector('.step-item:nth-of-type(5) a:not([disabled])')
expect(page).to_not have_selector('.step-item:nth-of-type(5).active')
click_link('Subject')
end
expect(page).to have_content "Create new subject"
Expand All @@ -76,35 +78,7 @@
context 'with a walk with a subject' do
let!(:user) { FactoryBot.create(:user) }
let!(:walk) { FactoryBot.create(:walk,
user: user,
courseline: [[12, 12], [12.1, 12]]) }
let!(:stations) { FactoryBot.create_list(:station, 2,
user: user,
walk_id: walk.id,
next: 1) }
let!(:subject) { FactoryBot.create(:subject, user: user,
station: stations.first) }

scenario 'click on page link', js: true do
sign_in user
visit "/en/walks/#{walk.id}"
expect(page).to have_content "You cannot publish your walk right now."

within '.walk-publish-container' do
expect(page).to have_selector('.step-item:nth-of-type(4).active')
expect(page).to have_selector('.step-item:nth-of-type(5) a:not([disabled])')
click_link('Page')
end
expect(page).to have_content "Create new page"
end
end


context 'with a walk with a subject' do
let!(:user) { FactoryBot.create(:user) }
let!(:walk) { FactoryBot.create(:walk,
user: user,
courseline: [[12, 12], [12.1, 12]]) }
user: user) }
let!(:stations) { FactoryBot.create_list(:station, 2,
user: user,
walk_id: walk.id,
Expand All @@ -118,7 +92,8 @@
expect(page).to have_content "You cannot publish your walk right now."

within '.walk-publish-container' do
expect(page).to have_selector('.step-item:nth-of-type(4).active')
expect(page).to have_selector('.step-item:nth-of-type(3).active')
expect(page).to have_selector('.step-item:nth-of-type(4) a:not([disabled])')
expect(page).to have_selector('.step-item:nth-of-type(5) a:not([disabled])')
click_link('Page')
end
Expand Down
13 changes: 9 additions & 4 deletions spec/helpers/walks_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
end

it 'returns station if at least 2 stations were created' do
walk_mock = double(stations: [1, 2], courseline: nil)
walk_mock = double(stations: double(
count: 2,
first: double(subjects: false)),
courseline: nil)
expect(helper.walks_public_status_helper(walk_mock)).to eq('station')
end

it 'returns courseline if courseline was set' do
walk_mock = double(stations: double(
first: double(subjects: false),
first: double(subjects: double(
first: double(
pages: true))),
count: 2),
courseline: [[12, 12], [12, 12.1]])
expect(helper.walks_public_status_helper(walk_mock)).to eq('courseline')
Expand All @@ -26,7 +31,7 @@
first: double(
pages: false))),
count: 2),
courseline: [[12, 12], [12, 12.1]])
courseline: nil)
expect(helper.walks_public_status_helper(walk_mock)).to eq('subject')
end

Expand All @@ -36,7 +41,7 @@
first: double(
pages: true))),
count: 2),
courseline: [[12, 12], [12, 12.1]])
courseline: nil)
expect(helper.walks_public_status_helper(walk_mock)).to eq('page')
end
end
Expand Down

0 comments on commit 8f916df

Please sign in to comment.