Skip to content

Commit

Permalink
Merge bbb3b84 into 2f47aec
Browse files Browse the repository at this point in the history
  • Loading branch information
lislis committed Sep 11, 2018
2 parents 2f47aec + bbb3b84 commit 04c2895
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/util.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
.space-t {
margin-top: 2rem;
}
.space-b {
margin-bottom: 2rem;
}

.no-m {
margin: 0;
Expand Down
16 changes: 16 additions & 0 deletions app/helpers/walks_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
module WalksHelper
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'
end
end
end
end
walk_status
end
end
8 changes: 8 additions & 0 deletions app/models/walk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ class Walk < ApplicationRecord
def editable_by?(current_user)
(current_user) && (user == current_user || current_user.admin?)
end

def publishable?
stations.count >= 2 &&
courseline.present? &&
stations.first.subjects.present? &&
stations.first.subjects.first.pages.present? &&
!public
end
end
6 changes: 1 addition & 5 deletions app/views/walks/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
<p><%= t 'walk.form.help.description' %></p>
</div>

<% if action_name == 'new' %>
<p class="bg-gray p-2"><%= t 'walk.form.help.step' %></p>
<% end %>
<% if action_name == 'edit' %>
<% if @walk.publishable? || @walk.public %>
<div class="form-group">
<%= f.label :public, class: 'form-checkbox' do %>
<%= f.check_box :public %>
Expand Down
66 changes: 66 additions & 0 deletions app/views/walks/_public_status.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<div class="container space-b walk-publish-container">
<div class="columns">
<% if @walk.publishable? %>
<div class="column col-6 col-md-10 col-mx-auto box">
<div class="columns">
<div class="column col-10">
<p class="va-middle m-2"><%= t('walk.publish.can') %></p>
</div>
<div class="column col-2 text-right">
<%= render "walks/publish"%>
</div>
</div>
</div>
<% else %>
<div class="column col-12 box">
<p class="mt-2"><%= t('walk.publish.cannot') %></p>
<ul class="step mt-2 mb-2">
<li class="step-item <%= 'active' if walks_public_status_helper(@walk) == 'walk' %>">
<%= link_to t('walk.singular'), walk_path(@walk),
data: { tooltip: t('walk.publish.step_walk') },
class: "tooltip"%>
</li>

<li class="step-item <%= 'active' if walks_public_status_helper(@walk) == 'station' %>">
<%= link_to t('station.singular'), new_walk_station_path(@walk),
data: { tooltip: t('walk.publish.step_station') },
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),
data: { tooltip: t('walk.publish.step_subject') },
class: "tooltip"%>
<% else %>
<a disabled="disabled" class="tooltip"
data-tooltip="<%= t('walk.publish.step_subject')%>"><%= t('subject.singular') %></a>
<% end %>
</li>

<li class="step-item <%= 'active' if walks_public_status_helper(@walk) == 'page' %>">
<% if @walk.stations.first.present? && @walk.stations.first.subjects.first.present? %>
<%= link_to t('page.singular'), new_subject_page_path(@walk.stations.first.subjects.first),
data: { tooltip: t('walk.publish.step_page') },
class: "tooltip"%>
<% else %>
<a disabled="disabled" class="tooltip"
data-tooltip="<%= t('walk.publish.step_page') %>"><%= t('page.singular') %></a>
<% end %>
</li>
</ul>
</div>
<% end %>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/walks/_publish.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= form_for :walk, method: :patch, url: walk_path(@walk), html: { class: 'd-inline' } do |f| %>
<%= f.hidden_field :public %>
<button class="btn btn-secondary tooltip"
data-tooltip="<%= t('walk.publish.btn_tooltip')%>"><i data-feather="globe"></i></button>
<% end %>
13 changes: 11 additions & 2 deletions app/views/walks/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<div class="container">
<%= render 'walks/public_status' unless @walk.public %>

<div class="container walk-container">
<div class="columns">
<div class="column col-7 col-md-12 col-mr-auto">
<div class="columns">
<div class="column col-8">
<h1><%= @walk.name %></h1>
<h1>
<% if @walk.public %>
<span class="tooltip va-middle"
data-tooltip="<%= t('walk.public') %>">
<i data-feather="globe"></i></span>
<% end %>
<%= @walk.name %>
</h1>
<p><%= @walk.location %></p>
<p><%= @walk.description %></p>
</div>
Expand Down
10 changes: 10 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,18 @@ de:
delete: "Spaziergang löschen"
deleted: "Spaziergang gelöscht!"
public: "öffentlich"
publish:
btn_tooltip: "Spaziergang veröffentlichen"
can: "Du kannst den spaziergang jetzt veröffentlichen."
cannot: "Du kannst deinen Spaziergang noch nicht veröffentlichen."
step_walk: "Spaziergang erstellt"
step_station: "Mindestens 2 Stationen hinzugefügt"
step_course: "Laufroute hinzugefügt"
step_subject: "Mindestens 1 Thema hinzugefügt"
step_page: "Mindestens 1 Seite hinzugefügt"
made_by: "erstellt von"
course:
name: "Laufroute"
label: "Route festlegen"
title: "Route festlegen für"
reset: "Laufroute zurücksetzen"
Expand Down
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,18 @@ en:
delete: "Delete walk"
deleted: "Walk deleted!"
public: "public"
publish:
btn_tooltip: "Publish walk"
can: "You can publish your walk now."
cannot: "You cannot publish your walk right now."
step_walk: "Walk created"
step_station: "Added at least 2 stations"
step_course: "Set route"
step_subject: "Added at last 1 topic"
step_page: "Added at least 1 page"
made_by: "created by"
course:
name: "Route"
label: "Set route"
title: "Set route for"
reset: "Reset route"
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :user do
username { Faker::Seinfeld.character.split(' ').first }
username { Faker::Seinfeld.character.downcase.split(' ').first }
email { Faker::Internet.email }
password 'testtesttest'
end
Expand Down
8 changes: 6 additions & 2 deletions spec/features/order_stations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

scenario 'cannot find route button' do
sign_in_go_to_walk_page
expect(page).to_not have_css('[data-tooltip="Set route"]')
within '.walk-container' do
expect(page).to_not have_css('[data-tooltip="Set route"]')
end
end
end

Expand Down Expand Up @@ -49,7 +51,9 @@ def sign_in_go_to_walk_page
end

def click_route_btn_get_redirected_to_order
find('[data-tooltip="Set route"]').click
within '.walk-container' do
find('[data-tooltip="Set route"]').click
end
expect(page).to have_content I18n.t('walk.notice.force_sort')
expect(page).to have_content I18n.t('walk.course.title')
click_button I18n.t('station.save_order')
Expand Down
157 changes: 157 additions & 0 deletions spec/features/publish_walk_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# coding: utf-8
require 'rails_helper'

RSpec.feature 'Publish a walk', type: :feature do
context 'with a fresh walk' do
let!(:user) { FactoryBot.create(:user) }
let!(:walk) { FactoryBot.create(:walk, user: user) }

scenario 'click on station link', js: true do
sign_in user
visit "/en/walks/#{walk.id}"
within '.walk-container' do
expect(page).to have_content(walk.name)
end
expect(page).to have_selector('.walk-publish-container')
expect(page).to have_content I18n.t('walk.publish.cannot')

within '.walk-publish-container' do
expect(page).to have_selector('.step-item:first-of-type.active')
expect(page).to_not have_selector('.step-item:nth-of-type(3) a:not([disabled])')
click_link('Station')
end
expect(page).to have_content(I18n.t('station.new'))

end
end

context 'with a walk with stations' do
let!(:user) { FactoryBot.create(:user) }
let!(:walk) { FactoryBot.create(:walk, user: user) }
let!(:stations) { FactoryBot.create_list(:station, 2,
user: user,
walk_id: walk.id,
next: 1) }

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

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])')
click_link('Route')
end
expect(page).to have_content(I18n.t('walk.course.label'))
end
end

context 'with a walk with courseline' 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) }

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

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(4) a:not([disabled])')
expect(page).to_not have_selector('.step-item:nth-of-type(5) a:not([disabled])')
click_link('Subject')
end
expect(page).to have_content(I18n.t('subject.new_verb'))
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]]) }
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 I18n.t('walk.publish.cannot')

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(I18n.t('page.new_verb'))
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]]) }
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 I18n.t('walk.publish.cannot')

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(I18n.t('page.new_verb'))
end
end

pending 'with a publishable walk' do
let!(:user) { FactoryBot.create(:user, username: 'foobi') }
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_id: stations.first.id) }
let!(:page) { FactoryBot.create(:page, user: user,
subject_id: subject.id) }

scenario 'click on publish button', js: true do
sign_in user
visit "/en/walks/#{walk.id}"
click_link 'Your walks'
click_link walk.name
expect(page).to have_content I18n.t('walk.publish.can')

within '.walk-publish-container' do
find('[data-tooltip="Publish walk"]').click
end
expect(page).to_not have_content I18n.t('walk.publish.can')
expect(page).to_not have_selector '.walk-publish-container'
expect(page).to have_selector '.walk-container span[data-tooltip="public"]'
end
end
end
Loading

0 comments on commit 04c2895

Please sign in to comment.