diff options
Diffstat (limited to 'spec')
34 files changed, 869 insertions, 333 deletions
diff --git a/spec/controllers/autocomplete_calendars_controller_spec.rb b/spec/controllers/autocomplete_calendars_controller_spec.rb index 3ff75fadf..812cd92f9 100644 --- a/spec/controllers/autocomplete_calendars_controller_spec.rb +++ b/spec/controllers/autocomplete_calendars_controller_spec.rb @@ -1,5 +1,3 @@ -require 'rails_helper' - RSpec.describe AutocompleteCalendarsController, type: :controller do end diff --git a/spec/factories/chouette_2_factories.rb b/spec/factories/chouette_2_factories.rb deleted file mode 100644 index e8eba13e6..000000000 --- a/spec/factories/chouette_2_factories.rb +++ /dev/null @@ -1,79 +0,0 @@ -FactoryGirl.define do - - factory :organisation do - sequence(:name) { |n| "Organisation #{n}" } - sequence(:code) { |n| "000#{n}" } - end - - factory :referential do - sequence(:name) { |n| "Test #{n}" } - sequence(:slug) { |n| "test_#{n}" } - sequence(:prefix) { |n| "test_#{n}" } - association :organisation - association :workbench - association :line_referential - association :stop_area_referential - time_zone "Europe/Paris" - end - - factory :rule_parameter_set do - sequence(:name) { |n| "Test #{n}" } - association :organisation - after(:create) do |rsp| - rsp.parameters = RuleParameterSet.default_for_all_modes( rsp.organisation).parameters - end - end - - factory :user do - association :organisation - sequence(:name) { |n| "chouette#{n}" } - sequence(:username) { |n| "chouette#{n}" } - sequence(:email) { |n| "chouette#{n}@dryade.priv" } - password "secret" - password_confirmation "secret" - end - - factory :import_task do |f| - user_name "dummy" - user_id 123 - no_save false - format "Neptune" - resources { Rack::Test::UploadedFile.new 'spec/fixtures/neptune.zip', 'application/zip', false } - referential { Referential.find_by_slug("first") } - end - - factory :kml_export do - referential { Referential.find_by_slug("first") } - end - - factory :export do - referential { Referential.find_by_slug("first") } - end - - factory :export_log_message do - association :export - sequence(:key) { |n| "key_#{n}" } - end - - factory :vehicle_translation do - count 1 - duration 1 - end - - factory :compliance_check_result do - association :compliance_check_task - rule_code "2-NEPTUNE-StopArea-6" - severity "warning" - status "nok" - end - - factory :compliance_check_task do - user_id 1 - user_name "Dummy" - status "pending" - referential { Referential.find_by_slug("first") } - end - - factory :time_table_combination - -end diff --git a/spec/factories/clean_ups.rb b/spec/factories/clean_ups.rb index d3746c3b2..7107769ff 100644 --- a/spec/factories/clean_ups.rb +++ b/spec/factories/clean_ups.rb @@ -2,5 +2,6 @@ FactoryGirl.define do factory :clean_up do begin_date { Date.today} end_date { Date.today + 1.month } + date_type { :before } end end diff --git a/spec/factories/compliance_check_results.rb b/spec/factories/compliance_check_results.rb new file mode 100644 index 000000000..7a3a3e956 --- /dev/null +++ b/spec/factories/compliance_check_results.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :compliance_check_result do + association :compliance_check_task + rule_code "2-NEPTUNE-StopArea-6" + severity "warning" + status "nok" + end +end diff --git a/spec/factories/compliance_check_tasks.rb b/spec/factories/compliance_check_tasks.rb new file mode 100644 index 000000000..e9fdeb5ef --- /dev/null +++ b/spec/factories/compliance_check_tasks.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :compliance_check_task do + user_id 1 + user_name "Dummy" + status "pending" + referential { Referential.find_by_slug("first") } + end +end diff --git a/spec/factories/export_log_messages.rb b/spec/factories/export_log_messages.rb new file mode 100644 index 000000000..849efd7b1 --- /dev/null +++ b/spec/factories/export_log_messages.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :export_log_message do + association :export + sequence(:key) { |n| "key_#{n}" } + end +end diff --git a/spec/factories/exports.rb b/spec/factories/exports.rb new file mode 100644 index 000000000..34427edb8 --- /dev/null +++ b/spec/factories/exports.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :export do + referential { Referential.find_by_slug("first") } + end +end diff --git a/spec/factories/import_tasks.rb b/spec/factories/import_tasks.rb new file mode 100644 index 000000000..9ca6db899 --- /dev/null +++ b/spec/factories/import_tasks.rb @@ -0,0 +1,10 @@ +FactoryGirl.define do + factory :import_task do |f| + user_name "dummy" + user_id 123 + no_save false + format "Neptune" + resources { Rack::Test::UploadedFile.new 'spec/fixtures/neptune.zip', 'application/zip', false } + referential { Referential.find_by_slug("first") } + end +end diff --git a/spec/factories/kml_exports.rb b/spec/factories/kml_exports.rb new file mode 100644 index 000000000..feb86c5b6 --- /dev/null +++ b/spec/factories/kml_exports.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :kml_export do + referential { Referential.find_by_slug("first") } + end +end diff --git a/spec/factories/organisations.rb b/spec/factories/organisations.rb new file mode 100644 index 000000000..239557a0e --- /dev/null +++ b/spec/factories/organisations.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :organisation do + sequence(:name) { |n| "Organisation #{n}" } + sequence(:code) { |n| "000#{n}" } + end +end diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb new file mode 100644 index 000000000..dd5bf1c2e --- /dev/null +++ b/spec/factories/referentials.rb @@ -0,0 +1,12 @@ +FactoryGirl.define do + factory :referential do + sequence(:name) { |n| "Test #{n}" } + sequence(:slug) { |n| "test_#{n}" } + sequence(:prefix) { |n| "test_#{n}" } + association :organisation + association :workbench + association :line_referential + association :stop_area_referential + time_zone "Europe/Paris" + end +end diff --git a/spec/factories/rule_parameter_sets.rb b/spec/factories/rule_parameter_sets.rb new file mode 100644 index 000000000..e20fff8ce --- /dev/null +++ b/spec/factories/rule_parameter_sets.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :rule_parameter_set do + sequence(:name) { |n| "Test #{n}" } + association :organisation + after(:create) do |rsp| + rsp.parameters = RuleParameterSet.default_for_all_modes( rsp.organisation).parameters + end + end +end diff --git a/spec/factories/time_table_combinations.rb b/spec/factories/time_table_combinations.rb new file mode 100644 index 000000000..364d6460e --- /dev/null +++ b/spec/factories/time_table_combinations.rb @@ -0,0 +1,3 @@ +FactoryGirl.define do + factory :time_table_combination +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 000000000..8f0ec38c0 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,10 @@ +FactoryGirl.define do + factory :user do + association :organisation + sequence(:name) { |n| "chouette#{n}" } + sequence(:username) { |n| "chouette#{n}" } + sequence(:email) { |n| "chouette#{n}@dryade.priv" } + password "secret" + password_confirmation "secret" + end +end diff --git a/spec/factories/vehicle_translations.rb b/spec/factories/vehicle_translations.rb new file mode 100644 index 000000000..1f0175222 --- /dev/null +++ b/spec/factories/vehicle_translations.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :vehicle_translation do + count 1 + duration 1 + end +end diff --git a/spec/features/calendars_spec.rb b/spec/features/calendars_spec.rb deleted file mode 100644 index e15624295..000000000 --- a/spec/features/calendars_spec.rb +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- -require 'spec_helper' - -describe 'Calendars', type: :feature do - login_user - - let!(:calendars) { Array.new(2) { create :calendar, organisation_id: 1 } } - let!(:shared_calendar_other_org) { create :calendar, shared: true } - let!(:unshared_calendar_other_org) { create :calendar } - - describe 'index' do - before(:each) { visit calendars_path } - - it 'displays calendars of the current organisation' do - expect(page).to have_content(calendars.first.short_name) - # expect(page).to have_content(shared_calendar_other_org.short_name) - # expect(page).not_to have_content(unshared_calendar_other_org.short_name) - end - - context 'filtering' do - it 'supports filtering by short name' do - fill_in 'q[name_or_short_name_cont]', with: calendars.first.short_name - click_button 'search_btn' - expect(page).to have_content(calendars.first.short_name) - expect(page).not_to have_content(calendars.last.short_name) - end - - it 'supports filtering by name' do - fill_in 'q[name_or_short_name_cont]', with: calendars.first.name - click_button 'search_btn' - expect(page).to have_content(calendars.first.name) - expect(page).not_to have_content(calendars.last.name) - end - - - it 'supports filtering by shared' do - shared_calendar = create :calendar, organisation_id: 1, shared: true - visit calendars_path - # select I18n.t('true'), from: 'q[shared]' - find(:css, '#q_shared_true').set(true) - click_button 'filter_btn' - expect(page).to have_content(shared_calendar.short_name) - expect(page).not_to have_content(calendars.first.short_name) - end - - # wip - # it 'supports filtering by date' do - # july_calendar = create :calendar, dates: [Date.new(2017, 7, 7)], date_ranges: [Date.new(2017, 7, 15)..Date.new(2017, 7, 30)], organisation_id: 1 - # visit calendars_path - # select '7', from: 'q_contains_date_3i' - # select 'juillet', from: 'q_contains_date_2i' - # select '2017', from: 'q_contains_date_1i' - # click_button 'filter_btn' - # expect(page).to have_content(july_calendar.short_name) - # expect(page).not_to have_content(calendars.first.short_name) - # select '18', from: 'q_contains_date_3i' - # select 'juillet', from: 'q_contains_date_2i' - # select '2017', from: 'q_contains_date_1i' - # click_button 'filter_btn' - # expect(page).to have_content(july_calendar.short_name) - # expect(page).not_to have_content(calendars.first.short_name) - # end - end - end - - describe 'show' do - it 'displays calendar' do - visit calendar_path(calendars.first) - expect(page).to have_content(calendars.first.name) - end - end -end diff --git a/spec/features/referentials_permissions_spec.rb b/spec/features/referentials_permissions_spec.rb index 0216eeeb0..c37dff5b9 100644 --- a/spec/features/referentials_permissions_spec.rb +++ b/spec/features/referentials_permissions_spec.rb @@ -31,7 +31,7 @@ describe "Referentials", :type => :feature do end it 'shows the delete button' do expected_href = referential_path(referential) - expect( page ).to have_css(%{a[href=#{expected_href.inspect}] span}, text: destroy_link_text) + expect( page ).to have_css(%{a[href=#{expected_href.inspect}]}, text: destroy_link_text) end end diff --git a/spec/helpers/table_builder_helper/column_spec.rb b/spec/helpers/table_builder_helper/column_spec.rb new file mode 100644 index 000000000..0f27703b2 --- /dev/null +++ b/spec/helpers/table_builder_helper/column_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe TableBuilderHelper::Column do + describe "#header_label" do + it "returns the column @name if present" do + expect( + TableBuilderHelper::Column.new( + name: 'ID Codif', + attribute: nil + ).header_label + ).to eq('ID Codif') + end + + it "returns the I18n translation of @key if @name not present" do + expect( + TableBuilderHelper::Column.new( + key: :phone, + attribute: 'phone' + ).header_label(Chouette::Company) + ).to eq('Numéro de téléphone') + end + end +end diff --git a/spec/helpers/table_builder_helper/custom_links_spec.rb b/spec/helpers/table_builder_helper/custom_links_spec.rb new file mode 100644 index 000000000..b64e97527 --- /dev/null +++ b/spec/helpers/table_builder_helper/custom_links_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe TableBuilderHelper::CustomLinks do + describe "#actions_after_policy_check" do + it "includes :show" do + referential = build_stubbed(:referential) + user_context = UserContext.new( + build_stubbed( + :user, + organisation: referential.organisation, + permissions: [ + 'boiv:read-offer' + ] + ), + referential: referential + ) + + expect( + TableBuilderHelper::CustomLinks.new( + referential, + user_context, + [:show] + ).actions_after_policy_check + ).to eq([:show]) + end + end +end diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb new file mode 100644 index 000000000..8f4d98c88 --- /dev/null +++ b/spec/helpers/table_builder_helper_spec.rb @@ -0,0 +1,371 @@ +require 'htmlbeautifier' + +module TableBuilderHelper + include Pundit +end + +describe TableBuilderHelper, type: :helper do + describe "#table_builder_2" do + it "builds a table" do + referential = build_stubbed(:referential) + workbench = referential.workbench + + user_context = UserContext.new( + build_stubbed( + :user, + organisation: referential.organisation, + permissions: [ + 'referentials.create', + 'referentials.edit', + 'referentials.destroy' + ] + ), + referential: referential + ) + allow(helper).to receive(:current_user).and_return(user_context) + + referentials = [referential] + + allow(referentials).to receive(:model).and_return(Referential) + + allow(helper).to receive(:params).and_return({ + controller: 'workbenches', + action: 'show', + id: referentials[0].workbench.id + }) + + referentials = ModelDecorator.decorate( + referentials, + with: ReferentialDecorator + ) + + expected = <<-HTML +<table class="table has-filter has-search"> + <thead> + <tr> + <th> + <div class="checkbox"><input type="checkbox" name="0" id="0" value="all" /><label for="0"></label></div> + </th> + <th><a href="/workbenches/#{workbench.id}?direction=desc&sort=name">Nom<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/#{workbench.id}?direction=desc&sort=status">Etat<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/#{workbench.id}?direction=desc&sort=organisation">Organisation<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/#{workbench.id}?direction=desc&sort=validity_period">Période de validité englobante<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/#{workbench.id}?direction=desc&sort=lines">Lignes<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/#{workbench.id}?direction=desc&sort=created_at">Créé le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/#{workbench.id}?direction=desc&sort=updated_at">Edité le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/#{workbench.id}?direction=desc&sort=published_at">Intégré le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th></th> + </tr> + </thead> + <tbody> + <tr> + <td> + <div class="checkbox"><input type="checkbox" name="#{referential.id}" id="#{referential.id}" value="#{referential.id}" /><label for="#{referential.id}"></label></div> + </td> + <td title="Voir"><a href="/referentials/#{referential.id}">#{referential.name}</a></td> + <td> + <div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>En préparation</span></div> + </td> + <td>#{referential.organisation.name}</td> + <td>-</td> + <td>#{referential.lines.count}</td> + <td>#{I18n.localize(referential.created_at, format: :short)}</td> + <td>#{I18n.localize(referential.updated_at, format: :short)}</td> + <td></td> + <td class="actions"> + <div class="btn-group"> + <div class="btn dropdown-toggle" data-toggle="dropdown"><span class="fa fa-cog"></span></div> + <ul class="dropdown-menu"> + <li><a href="/referentials/#{referential.id}">Consulter</a></li> + <li><a href="/referentials/#{referential.id}/edit">Editer</a></li> + <li><a href="/referentials/#{referential.id}/time_tables">Calendriers</a></li> + <li><a href="/referentials/new?from=#{referential.id}">Dupliquer</a></li> + <li><a rel="nofollow" data-method="put" href="/referentials/#{referential.id}/archive">Conserver</a></li> + <li class="delete-action"><a data-confirm="Etes vous sûr de vouloir supprimer ce jeu de données ?" rel="nofollow" data-method="delete" href="/referentials/#{referential.id}"><span class="fa fa-trash"></span>Supprimer</a></li> + </ul> + </div> + </td> + </tr> + </tbody> +</table> + HTML + + html_str = helper.table_builder_2( + referentials, + [ + TableBuilderHelper::Column.new( + key: :name, + attribute: 'name' + ), + TableBuilderHelper::Column.new( + key: :status, + attribute: Proc.new do |w| + if w.archived? + ("<div class='td-block'><span class='fa fa-archive'></span><span>Conservé</span></div>").html_safe + else + ("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>En préparation</span></div>").html_safe + end + end + ), + TableBuilderHelper::Column.new( + key: :organisation, + attribute: Proc.new {|w| w.organisation.name} + ), + TableBuilderHelper::Column.new( + key: :validity_period, + attribute: Proc.new do |w| + if w.validity_period.nil? + '-' + else + t( + 'validity_range', + debut: l(w.try(:validity_period).try(:begin), format: :short), + end: l(w.try(:validity_period).try(:end), format: :short) + ) + end + end + ), + TableBuilderHelper::Column.new( + key: :lines, + attribute: Proc.new {|w| w.lines.count} + ), + TableBuilderHelper::Column.new( + key: :created_at, + attribute: Proc.new {|w| l(w.created_at, format: :short)} + ), + TableBuilderHelper::Column.new( + key: :updated_at, + attribute: Proc.new {|w| l(w.updated_at, format: :short)} + ), + TableBuilderHelper::Column.new( + key: :published_at, + attribute: '' + ) + ], + selectable: true, + links: [:show, :edit], + cls: 'table has-filter has-search' + ) + + beautified_html = HtmlBeautifier.beautify(html_str, indent: ' ') + + expect(beautified_html).to eq(expected.chomp) + end + + it "can set a column as non-sortable" do + company = build_stubbed(:company) + line_referential = build_stubbed( + :line_referential, + companies: [company] + ) + referential = build_stubbed( + :referential, + line_referential: line_referential + ) + + user_context = UserContext.new( + build_stubbed( + :user, + organisation: referential.organisation, + permissions: [ + 'referentials.create', + 'referentials.edit', + 'referentials.destroy' + ] + ), + referential: referential + ) + allow(helper).to receive(:current_user).and_return(user_context) + allow(TableBuilderHelper::URL).to receive(:current_referential) + .and_return(referential) + + companies = [company] + + allow(companies).to receive(:model).and_return(Chouette::Company) + + allow(helper).to receive(:params).and_return({ + controller: 'referential_companies', + action: 'index', + referential_id: referential.id + }) + + companies = ModelDecorator.decorate( + companies, + with: CompanyDecorator + ) + + expected = <<-HTML +<table class="table has-search"> + <thead> + <tr> + <th>ID Codif</th> + <th><a href="/referentials/#{referential.id}/companies?direction=desc&sort=name">Nom<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/referentials/#{referential.id}/companies?direction=desc&sort=phone">Numéro de téléphone<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/referentials/#{referential.id}/companies?direction=desc&sort=email">Email<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/referentials/#{referential.id}/companies?direction=desc&sort=url">Page web associée<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th></th> + </tr> + </thead> + <tbody> + <tr> + <td>#{company.objectid.local_id}</td> + <td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td> + <td></td> + <td></td> + <td></td> + <td class="actions"> + <div class="btn-group"> + <div class="btn dropdown-toggle" data-toggle="dropdown"><span class="fa fa-cog"></span></div> + <ul class="dropdown-menu"> + <li><a href="/referentials/#{referential.id}/companies/#{company.id}">Consulter</a></li> + </ul> + </div> + </td> + </tr> + </tbody> +</table> + HTML + + html_str = helper.table_builder_2( + companies, + [ + TableBuilderHelper::Column.new( + name: 'ID Codif', + attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, + sortable: false + ), + TableBuilderHelper::Column.new( + key: :name, + attribute: 'name' + ), + TableBuilderHelper::Column.new( + key: :phone, + attribute: 'phone' + ), + TableBuilderHelper::Column.new( + key: :email, + attribute: 'email' + ), + TableBuilderHelper::Column.new( + key: :url, + attribute: 'url' + ), + ], + links: [:show, :edit, :delete], + cls: 'table has-search' + ) + + beautified_html = HtmlBeautifier.beautify(html_str, indent: ' ') + + expect(beautified_html).to eq(expected.chomp) + end + + it "can set all columns as non-sortable" do + company = build_stubbed(:company) + line_referential = build_stubbed( + :line_referential, + companies: [company] + ) + referential = build_stubbed( + :referential, + line_referential: line_referential + ) + + user_context = UserContext.new( + build_stubbed( + :user, + organisation: referential.organisation, + permissions: [ + 'referentials.create', + 'referentials.edit', + 'referentials.destroy' + ] + ), + referential: referential + ) + allow(helper).to receive(:current_user).and_return(user_context) + allow(TableBuilderHelper::URL).to receive(:current_referential) + .and_return(referential) + + companies = [company] + + allow(companies).to receive(:model).and_return(Chouette::Company) + + allow(helper).to receive(:params).and_return({ + controller: 'referential_companies', + action: 'index', + referential_id: referential.id + }) + + companies = ModelDecorator.decorate( + companies, + with: CompanyDecorator + ) + + expected = <<-HTML +<table class="table has-search"> + <thead> + <tr> + <th>ID Codif</th> + <th>Nom</th> + <th>Numéro de téléphone</th> + <th>Email</th> + <th>Page web associée</th> + <th></th> + </tr> + </thead> + <tbody> + <tr> + <td>#{company.objectid.local_id}</td> + <td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td> + <td></td> + <td></td> + <td></td> + <td class="actions"> + <div class="btn-group"> + <div class="btn dropdown-toggle" data-toggle="dropdown"><span class="fa fa-cog"></span></div> + <ul class="dropdown-menu"> + <li><a href="/referentials/#{referential.id}/companies/#{company.id}">Consulter</a></li> + </ul> + </div> + </td> + </tr> + </tbody> +</table> + HTML + + html_str = helper.table_builder_2( + companies, + [ + TableBuilderHelper::Column.new( + name: 'ID Codif', + attribute: Proc.new { |n| n.try(:objectid).try(:local_id) } + ), + TableBuilderHelper::Column.new( + key: :name, + attribute: 'name' + ), + TableBuilderHelper::Column.new( + key: :phone, + attribute: 'phone' + ), + TableBuilderHelper::Column.new( + key: :email, + attribute: 'email' + ), + TableBuilderHelper::Column.new( + key: :url, + attribute: 'url' + ), + ], + sortable: false, + links: [:show, :edit, :delete], + cls: 'table has-search' + ) + + beautified_html = HtmlBeautifier.beautify(html_str, indent: ' ') + + expect(beautified_html).to eq(expected.chomp) + end + end +end diff --git a/spec/javascripts/spec_helper.coffee b/spec/javascripts/spec_helper.coffee new file mode 100644 index 000000000..9ff516885 --- /dev/null +++ b/spec/javascripts/spec_helper.coffee @@ -0,0 +1,32 @@ +# Teaspoon includes some support files, but you can use anything from your own support path too. +# require support/jasmine-jquery-1.7.0 +# require support/jasmine-jquery-2.0.0 +# require support/jasmine-jquery-2.1.0 +# require support/sinon +# require support/your-support-file +# +# PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion. +# Use this polyfill to avoid the confusion. +#= require support/phantomjs-shims +# +# You can require your own javascript files here. By default this will include everything in application, however you +# may get better load performance if you require the specific files that are being used in the spec that tests them. +#= require application +# +# Deferring execution +# If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call +# Teaspoon.execute() after everything has been loaded. Simple example of a timeout: +# +# Teaspoon.defer = true +# setTimeout(Teaspoon.execute, 1000) +# +# Matching files +# By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your +# spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the +# configuration in teaspoon_env.rb +# +# Manifest +# If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in +# the configuration and use this file as a manifest. +# +# For more information: http://github.com/modeset/teaspoon diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 19f65046f..d96baf8ef 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -188,11 +188,13 @@ describe('when clicking on validate button inside editing modal', () => { describe('when clicking on validate button inside duplicating modal', () => { it('should create an action to duplicate a vehiclejourney schedule', () => { const data = {} + const departureDelta = 0 const expectedAction = { type: 'DUPLICATE_VEHICLEJOURNEY', - data + data, + departureDelta } - expect(actions.duplicateVehicleJourney(data)).toEqual(expectedAction) + expect(actions.duplicateVehicleJourney(data, departureDelta)).toEqual(expectedAction) }) }) describe('when clicking on edit notes modal', () => { diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js index 2ab88386a..0a6729c8b 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -31,7 +31,7 @@ describe('filters reducer', () => { vehicleJourney: {}, timetable: {}, withoutSchedule: true, - withoutTimeTable: false + withoutTimeTable: true }, queryString: '' } @@ -153,7 +153,7 @@ describe('filters reducer', () => { "&q%5Bvehicle_journey_at_stops_departure_time_gteq%5D=11%3A11", "&q%5Bvehicle_journey_at_stops_departure_time_lteq%5D=22%3A22", "&q%5Bvehicle_journey_without_departure_time%5D=true", - "&q%5Bvehicle_journey_without_time_table%5D=false" + "&q%5Bvehicle_journey_without_time_table%5D=true" ].join('') expect( diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 23ebc3d9f..620e2ffdd 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -216,14 +216,15 @@ describe('vehicleJourneys reducer', () => { delta: 627, arrival_time : { hour: '12', - minute: '00' + minute: '01' }, departure_time : { hour: '22', - minute: '27' + minute: '28' }, stop_area_object_id : "FR:92024:ZDE:420553:STIF" }] + let departureDelta = 1 let fakeData = { duplicate_number: {value : 1}, additional_time: {value: '5'} @@ -234,7 +235,8 @@ describe('vehicleJourneys reducer', () => { expect( vjReducer(state, { type: 'DUPLICATE_VEHICLEJOURNEY', - data: fakeData + data: fakeData, + departureDelta }) ).toEqual([state[0], newVJ, state[1]]) }) diff --git a/spec/models/calendar/date_value_spec.rb b/spec/models/calendar/date_value_spec.rb new file mode 100644 index 000000000..70dca3cc6 --- /dev/null +++ b/spec/models/calendar/date_value_spec.rb @@ -0,0 +1,35 @@ +RSpec.describe Calendar::DateValue, type: :model do + describe 'DateValue' do + subject { date_value } + + def date_value(attributes = {}) + @__date_values__ ||= Hash.new + @__date_values__.fetch(attributes) do + @__date_values__[attributes] = Calendar::DateValue.new(attributes) + end + end + + it 'should support mark_for_destruction (required by cocoon)' do + date_value.mark_for_destruction + expect(date_value).to be_marked_for_destruction + end + + it 'should support _destroy attribute (required by coocon)' do + date_value._destroy = true + expect(date_value).to be_marked_for_destruction + end + + it 'should support new_record? (required by cocoon)' do + expect(Calendar::DateValue.new).to be_new_record + expect(date_value(id: 42)).not_to be_new_record + end + + it 'should cast value as date attribute' do + expect(date_value(value: '2017-01-03').value).to eq(Date.new(2017,01,03)) + end + + it 'validates presence' do + is_expected.to validate_presence_of(:value) + end + end +end diff --git a/spec/models/calendar/period_spec.rb b/spec/models/calendar/period_spec.rb new file mode 100644 index 000000000..233733cbf --- /dev/null +++ b/spec/models/calendar/period_spec.rb @@ -0,0 +1,68 @@ +RSpec.describe Calendar::Period, type: :model do + + + subject { period } + + def period(attributes = {}) + @__period__ ||= {} + @__period__.fetch(attributes){ + @__period__[attributes] = Calendar::Period.new(attributes) + } + end + + it 'should support mark_for_destruction (required by cocoon)' do + period.mark_for_destruction + expect(period).to be_marked_for_destruction + end + + it 'should support _destroy attribute (required by coocon)' do + period._destroy = true + expect(period).to be_marked_for_destruction + end + + it 'should support new_record? (required by cocoon)' do + expect(Calendar::Period.new).to be_new_record + expect(period(id: 42)).not_to be_new_record + end + + it 'should cast begin as date attribute' do + expect(period(begin: '2016-11-22').begin).to eq(Date.new(2016,11,22)) + end + + it 'should cast end as date attribute' do + expect(period(end: '2016-11-22').end).to eq(Date.new(2016,11,22)) + end + + it { is_expected.to validate_presence_of(:begin) } + it { is_expected.to validate_presence_of(:end) } + + it 'should validate that end is greather than or equlals to begin' do + expect(period(begin: '2016-11-21', end: '2016-11-22')).to be_valid + expect(period(begin: '2016-11-21', end: '2016-11-21')).to_not be_valid + expect(period(begin: '2016-11-22', end: '2016-11-21')).to_not be_valid + end + + describe 'intersect?' do + it 'should detect date in common with other date_ranges' do + november = period(begin: '2016-11-01', end: '2016-11-30') + mid_november_mid_december = period(begin: '2016-11-15', end: '2016-12-15') + expect(november.intersect?(mid_november_mid_december)).to be(true) + end + + it 'should not intersect when no date is in common' do + november = period(begin: '2016-11-01', end: '2016-11-30') + december = period(begin: '2016-12-01', end: '2016-12-31') + + expect(november.intersect?(december)).to be(false) + + january = period(begin: '2017-01-01', end: '2017-01-31') + expect(november.intersect?(december, january)).to be(false) + end + + it 'should not intersect itself' do + period = period(id: 42, begin: '2016-11-01', end: '2016-11-30') + expect(period.intersect?(period)).to be(false) + end + + end +end diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb index 33d9676cd..cf7e4aa27 100644 --- a/spec/models/calendar_spec.rb +++ b/spec/models/calendar_spec.rb @@ -1,5 +1,3 @@ -require 'rails_helper' - RSpec.describe Calendar, :type => :model do it { should belong_to(:organisation) } @@ -23,134 +21,25 @@ RSpec.describe Calendar, :type => :model do describe 'validations' do it 'validates that dates and date_ranges do not overlap' do - calendar = build(:calendar, dates: [Date.today], date_ranges: [Date.today..Date.tomorrow]) - expect { - calendar.save! - }.to raise_error(ActiveRecord::RecordInvalid) + expect(build(:calendar, dates: [Date.today], date_ranges: [Date.today..Date.tomorrow])).to_not be_valid end it 'validates that there are no duplicates in dates' do - calendar = build(:calendar, dates: [Date.yesterday, Date.yesterday], date_ranges: [Date.today..Date.tomorrow]) - expect { - calendar.save! - }.to raise_error(ActiveRecord::RecordInvalid) + expect(build(:calendar, dates: [Date.yesterday, Date.yesterday], date_ranges: [Date.today..Date.tomorrow])).to_not be_valid end end - describe 'Period' do - - subject { period } - - def period(attributes = {}) - return @period if attributes.empty? and @period - Calendar::Period.new(attributes).tap do |period| - @period = period if attributes.empty? - end - end - - it 'should support mark_for_destruction (required by cocoon)' do - period.mark_for_destruction - expect(period).to be_marked_for_destruction - end - - it 'should support _destroy attribute (required by coocon)' do - period._destroy = true - expect(period).to be_marked_for_destruction - end - - it 'should support new_record? (required by cocoon)' do - expect(Calendar::Period.new).to be_new_record - expect(period(id: 42)).not_to be_new_record - end - - it 'should cast begin as date attribute' do - expect(period(begin: '2016-11-22').begin).to eq(Date.new(2016,11,22)) - end - - it 'should cast end as date attribute' do - expect(period(end: '2016-11-22').end).to eq(Date.new(2016,11,22)) - end - - it { is_expected.to validate_presence_of(:begin) } - it { is_expected.to validate_presence_of(:end) } - - it 'should validate that end is greather than or equlals to begin' do - expect(period(begin: '2016-11-21', end: '2016-11-22')).to be_valid - expect(period(begin: '2016-11-21', end: '2016-11-21')).to be_valid - expect(period(begin: '2016-11-22', end: '2016-11-21')).to_not be_valid - end - - describe 'intersect?' do - it 'should detect date in common with other date_ranges' do - november = period(begin: '2016-11-01', end: '2016-11-30') - mid_november_mid_december = period(begin: '2016-11-15', end: '2016-12-15') - expect(november.intersect?(mid_november_mid_december)).to be(true) - end - - it 'should not intersect when no date is in common' do - november = period(begin: '2016-11-01', end: '2016-11-30') - december = period(begin: '2016-12-01', end: '2016-12-31') - - expect(november.intersect?(december)).to be(false) - - january = period(begin: '2017-01-01', end: '2017-01-31') - expect(november.intersect?(december, january)).to be(false) - end - - it 'should not intersect itself' do - period = period(id: 42, begin: '2016-11-01', end: '2016-11-30') - expect(period.intersect?(period)).to be(false) - end - - end - end describe 'before_validation' do let(:calendar) { create(:calendar, date_ranges: []) } it 'shoud fill date_ranges with date ranges' do - expected_ranges = [ - Range.new(Date.today, Date.tomorrow) - ] - expected_ranges.each_with_index do |range, index| - calendar.date_ranges << Calendar::Period.from_range(index, range) - end + expected_range = Date.today..Date.tomorrow + calendar.date_ranges << expected_range calendar.valid? - expect(calendar.date_ranges.map { |period| period.begin..period.end }).to eq(expected_ranges) + expect(calendar.date_ranges.map { |period| period.begin..period.end }).to eq([expected_range]) end end - describe 'DateValue' do - subject { date_value } - - def date_value(attributes = {}) - return @date_value if attributes.empty? and @date_value - Calendar::DateValue.new(attributes).tap do |date_value| - @date_value = date_value if attributes.empty? - end - end - - it 'should support mark_for_destruction (required by cocoon)' do - date_value.mark_for_destruction - expect(date_value).to be_marked_for_destruction - end - - it 'should support _destroy attribute (required by coocon)' do - date_value._destroy = true - expect(date_value).to be_marked_for_destruction - end - - it 'should support new_record? (required by cocoon)' do - expect(Calendar::DateValue.new).to be_new_record - expect(date_value(id: 42)).not_to be_new_record - end - - it 'should cast value as date attribute' do - expect(date_value(value: '2017-01-03').value).to eq(Date.new(2017,01,03)) - end - - it { is_expected.to validate_presence_of(:value) } - end end - diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb index 19b5060d2..aaf9a694f 100644 --- a/spec/models/chouette/journey_pattern_spec.rb +++ b/spec/models/chouette/journey_pattern_spec.rb @@ -2,6 +2,26 @@ require 'spec_helper' describe Chouette::JourneyPattern, :type => :model do + context 'validate minimum stop_points size' do + let(:journey_pattern) { create :journey_pattern } + let(:stop_points) { journey_pattern.stop_points } + + it 'should be valid if it has at least two sp' do + journey_pattern.stop_points.first(stop_points.size - 2).each do |sp| + journey_pattern.stop_points.delete(sp) + end + expect(journey_pattern).to be_valid + end + + it 'should not be valid if it has less then two sp' do + journey_pattern.stop_points.first(stop_points.size - 1).each do |sp| + journey_pattern.stop_points.delete(sp) + end + expect(journey_pattern).to_not be_valid + expect(journey_pattern.errors).to have_key(:stop_points) + end + end + describe "state_update" do def journey_pattern_to_state jp jp.attributes.slice('name', 'published_name', 'registration_number').tap do |item| @@ -24,12 +44,14 @@ describe Chouette::JourneyPattern, :type => :model do end it 'should attach checked stop_points' do - state['stop_points'].each{|sp| sp['checked'] = true} # Make sure journey_pattern has no stop_points - journey_pattern.stop_points.delete_all + state['stop_points'].each{|sp| sp['checked'] = false} + journey_pattern.state_stop_points_update(state) expect(journey_pattern.reload.stop_points).to be_empty + state['stop_points'].each{|sp| sp['checked'] = true} journey_pattern.state_stop_points_update(state) + expect(journey_pattern.reload.stop_points.count).to eq(5) end @@ -89,6 +111,63 @@ describe Chouette::JourneyPattern, :type => :model do expect(collection.first).to_not have_key('object_id') end + + it 'should create journey_pattern' do + new_state = journey_pattern_to_state(build(:journey_pattern, objectid: nil, route: route)) + Chouette::JourneyPattern.state_create_instance route, new_state + expect(new_state['object_id']).to be_truthy + expect(new_state['new_record']).to be_truthy + end + + it 'should delete journey_pattern' do + state['deletable'] = true + collection = [state] + expect { + Chouette::JourneyPattern.state_update route, collection + }.to change{Chouette::JourneyPattern.count}.from(1).to(0) + + expect(collection).to be_empty + end + + it 'should delete multiple journey_pattern' do + collection = 5.times.collect{journey_pattern_to_state(create(:journey_pattern, route: route))} + collection.map{|i| i['deletable'] = true} + + expect { + Chouette::JourneyPattern.state_update route, collection + }.to change{Chouette::JourneyPattern.count}.from(5).to(0) + end + + it 'should validate journey_pattern on update' do + journey_pattern.name = '' + collection = [state] + Chouette::JourneyPattern.state_update route, collection + expect(collection.first['errors']).to have_key(:name) + end + + it 'should validate journey_pattern on create' do + new_state = journey_pattern_to_state(build(:journey_pattern, name: '', objectid: nil, route: route)) + collection = [new_state] + expect { + Chouette::JourneyPattern.state_update route, collection + }.to_not change{Chouette::JourneyPattern.count} + + expect(collection.first['errors']).to have_key(:name) + expect(collection.first).to_not have_key('object_id') + end + + it 'should not save any journey_pattern of collection if one is invalid' do + journey_pattern.name = '' + valid_state = journey_pattern_to_state(build(:journey_pattern, objectid: nil, route: route)) + invalid_state = journey_pattern_to_state(journey_pattern) + collection = [valid_state, invalid_state] + + expect { + Chouette::JourneyPattern.state_update route, collection + }.to_not change{Chouette::JourneyPattern.count} + + expect(collection.first).to_not have_key('object_id') + end end describe "#stop_point_ids" do diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 7a8863cb3..76c5def5c 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -2,18 +2,74 @@ require 'spec_helper' describe Chouette::TimeTable, :type => :model do subject { create(:time_table) } + let(:subject_periods_to_range) { subject.periods.map{|p| p.period_start..p.period_end } } it { is_expected.to validate_presence_of :comment } it { is_expected.to validate_uniqueness_of :objectid } - context "merge with calendar" do - let(:calendar) { create(:calendar) } + describe "#merge! with time_table" do + let(:another_tt) { create(:time_table) } + let(:another_tt_periods_to_range) { another_tt.periods.map{|p| p.period_start..p.period_end } } + + # Make sur we don't have overlapping periods or dates + before do + another_tt.periods.each do |p| + p.period_start = p.period_start + 1.year + p.period_end = p.period_end + 1.year + end + another_tt.dates.each{| d| d.date = d.date + 1.year } + end + + it 'should merge dates' do + subject.dates.clear + subject.merge!(another_tt) + expect(subject.dates.map(&:date)).to include(*another_tt.dates.map(&:date)) + end + + it 'should merge periods' do + subject.periods.clear + subject.merge!(another_tt) + + expect(subject_periods_to_range).to include(*another_tt_periods_to_range) + end + + it 'should not modify int_day_types' do + int_day_types = subject.int_day_types + subject.merge!(another_tt) + expect(subject.int_day_types).to eq int_day_types + end + + it 'should merge date in_out false' do + another_tt.dates.last.in_out = false + another_tt.save + + subject.merge!(another_tt) + expect(subject.dates.map(&:date)).to include(another_tt.dates.last.date) + end + end + + context "#merge! with calendar" do + let(:calendar) { create(:calendar, date_ranges: [Date.today + 1.year..Date.tomorrow + 1.year]) } - it 'should add calendar dates to time_table' do + it 'should merge calendar dates' do subject.dates.clear subject.merge!(calendar.convert_to_time_table) expect(subject.dates.map(&:date)).to include(*calendar.dates) end + + it 'should merge calendar periods with no periods in source' do + subject.periods.clear + another_tt = calendar.convert_to_time_table + subject.merge!(another_tt) + expect(subject_periods_to_range).to include(*calendar.date_ranges) + end + + it 'should add calendar periods with existing periods in source' do + another_tt = calendar.convert_to_time_table + subject.merge!(another_tt) + + expect(subject_periods_to_range).to include(*calendar.date_ranges) + end end describe "actualize" do @@ -981,47 +1037,6 @@ end end end - - describe "#merge!" do - context "timetables have periods with common day_types " do - before do - subject.periods.clear - subject.dates.clear - subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,5)) - subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,6,30), :period_end => Date.new(2014,7,6)) - subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,16), :in_out => true) - subject.int_day_types = 4|16|32|128 - another_tt = create(:time_table , :int_day_types => (4|16|64|128) ) - another_tt.periods.clear - another_tt.dates.clear - another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,5), :period_end => Date.new(2014,8,12)) - another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,7,15), :period_end => Date.new(2014,7,25)) - subject.merge! another_tt - subject.reload - end - it "should have merged periods" do - expect(subject.periods.size).to eq(3) - expect(subject.periods[0].period_start).to eq(Date.new(2014, 6, 30)) - expect(subject.periods[0].period_end).to eq(Date.new(2014, 7, 6)) - expect(subject.periods[1].period_start).to eq(Date.new(2014, 7, 15)) - expect(subject.periods[1].period_end).to eq(Date.new(2014, 7, 25)) - expect(subject.periods[2].period_start).to eq(Date.new(2014, 8, 1)) - expect(subject.periods[2].period_end).to eq(Date.new(2014, 8, 12)) - end - it "should not modify day_types" do - expect(subject.int_day_types).to eq(4|16|128) - end - it "should have dates for thursdays and fridays" do - expect(subject.dates.size).to eq(4) - expect(subject.dates[0].date).to eq(Date.new(2014,7,3)) - expect(subject.dates[1].date).to eq(Date.new(2014,7,18)) - expect(subject.dates[2].date).to eq(Date.new(2014,7,25)) - expect(subject.dates[3].date).to eq(Date.new(2014,8,8)) - end - end - - end - describe "#intersect!" do context "timetables have periods with common day_types " do before do diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 8f9080b99..c78ef5b33 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -351,7 +351,7 @@ describe Chouette::VehicleJourney, :type => :model do end end - describe ".departure_time_between" do + describe ".where_departure_time_between" do it "selects vehicle journeys whose departure times are between the specified range" do journey_early = create( @@ -404,6 +404,35 @@ describe Chouette::VehicleJourney, :type => :model do .to_a ).to eq([journey]) end + + it "uses an inclusive range" do + journey_early = create( + :vehicle_journey, + stop_departure_time: '03:00:00' + ) + + route = journey_early.route + journey_pattern = journey_early.journey_pattern + + journey_late = create( + :vehicle_journey, + route: route, + journey_pattern: journey_pattern, + stop_departure_time: '04:00:00' + ) + + expect(route + .vehicle_journeys + .select('DISTINCT "vehicle_journeys".*') + .joins(' + LEFT JOIN "vehicle_journey_at_stops" + ON "vehicle_journey_at_stops"."vehicle_journey_id" = + "vehicle_journeys"."id" + ') + .where_departure_time_between('03:00', '04:00', allow_empty: true) + .to_a + ).to match_array([journey_early, journey_late]) + end end describe ".without_time_tables" do diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb index 4b1bf4da9..ee88ca773 100644 --- a/spec/models/clean_up_spec.rb +++ b/spec/models/clean_up_spec.rb @@ -191,7 +191,7 @@ RSpec.describe CleanUp, :type => :model do context '#destroy_time_tables' do let!(:time_table) { create(:time_table) } - let(:cleaner) { create(:clean_up, date_type: :before) } + let(:cleaner) { create(:clean_up) } it 'should destroy all time_tables' do expect{cleaner.destroy_time_tables(Chouette::TimeTable.all)}.to change { @@ -199,11 +199,26 @@ RSpec.describe CleanUp, :type => :model do }.by(-1) end - it 'should destroy associated vehicle_journeys' do - create(:vehicle_journey, time_tables: [time_table]) - expect{cleaner.destroy_time_tables(Chouette::TimeTable.all)}.to change { - Chouette::VehicleJourney.count - }.by(-1) + it 'should destroy time_table vehicle_journey association' do + vj = create(:vehicle_journey, time_tables: [time_table]) + cleaner.destroy_time_tables(Chouette::TimeTable.all) + expect(vj.reload.time_tables).to be_empty + end + end + + context '#destroy_vehicle_journey_without_time_table' do + let(:cleaner) { create(:clean_up) } + + it 'should destroy vehicle_journey' do + vj = create(:vehicle_journey) + expect{cleaner.destroy_vehicle_journey_without_time_table + }.to change { Chouette::VehicleJourney.count }.by(-1) + end + + it 'should not destroy vehicle_journey with time_table' do + create(:vehicle_journey, time_tables: [create(:time_table)]) + expect{cleaner.destroy_vehicle_journey_without_time_table + }.to_not change { Chouette::VehicleJourney.count } end end diff --git a/spec/support/pundit/policies.rb b/spec/support/pundit/policies.rb index e18309226..56433b2ee 100644 --- a/spec/support/pundit/policies.rb +++ b/spec/support/pundit/policies.rb @@ -9,7 +9,7 @@ module Support end def create_user_context(user:, referential:) - OpenStruct.new(user: user, context: {referential: referential}) + UserContext.new(user, referential: referential) end def add_permissions(*permissions, for_user:) diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb index 3a9efa0ce..7bc120f1a 100644 --- a/spec/views/lines/show.html.erb_spec.rb +++ b/spec/views/lines/show.html.erb_spec.rb @@ -3,7 +3,13 @@ require 'spec_helper' describe "/lines/show", :type => :view do assign_referential - let!(:line) { assign :line, create(:line) } + let!(:line) do + line = create(:line) + assign :line, line.decorate(context: { + line_referential: line.line_referential, + current_organisation: referential.organisation + }) + end let!(:line_referential) { assign :line_referential, line.line_referential } let!(:routes) { assign :routes, Array.new(2) { create(:route, :line => line) }.paginate } let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } diff --git a/spec/views/time_tables/show.html.erb_spec.rb b/spec/views/time_tables/show.html.erb_spec.rb index f429f9dec..edfb3f3cc 100644 --- a/spec/views/time_tables/show.html.erb_spec.rb +++ b/spec/views/time_tables/show.html.erb_spec.rb @@ -3,7 +3,14 @@ require 'spec_helper' describe "/time_tables/show", :type => :view do assign_referential - let!(:time_table) { assign(:time_table, create(:time_table)) } + let!(:time_table) do + assign( + :time_table, + create(:time_table).decorate(context: { + referential: referential + }) + ) + end let!(:year) { assign(:year, Date.today.cwyear) } let!(:time_table_combination) {assign(:time_table_combination, TimeTableCombination.new)} |
