From b44aeae726ad588edb3bfffe5bbaa1bde3b71f04 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 3 May 2018 09:16:55 +0200 Subject: Refs #6920; Activate Referentils created from scratch --- app/models/referential.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/referential.rb b/app/models/referential.rb index b4f64fad1..cabce85d6 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -322,6 +322,7 @@ class Referential < ApplicationModel before_create :create_schema after_create :clone_schema, if: :created_from + after_create :active!, unles: :created_from before_destroy :destroy_schema before_destroy :destroy_jobs -- cgit v1.2.3 From 6f7865568e74f8268d067c4f961ece9dd4a76d41 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 3 May 2018 09:17:31 +0200 Subject: Refs #6921; Show "Unarchive" action in referentials list --- app/decorators/referential_decorator.rb | 2 +- spec/decorators/referential_decorator_spec.rb | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb index e01987e59..db6261120 100644 --- a/app/decorators/referential_decorator.rb +++ b/app/decorators/referential_decorator.rb @@ -36,7 +36,7 @@ class ReferentialDecorator < AF83::Decorator l.method :put end - instance_decorator.action_link policy: :unarchive, secondary: :show, on: :show do |l| + instance_decorator.action_link policy: :unarchive, secondary: :show do |l| l.content t('actions.unarchive') l.href { h.unarchive_referential_path(object.id) } l.method :put diff --git a/spec/decorators/referential_decorator_spec.rb b/spec/decorators/referential_decorator_spec.rb index 98546f28b..88c7df666 100644 --- a/spec/decorators/referential_decorator_spec.rb +++ b/spec/decorators/referential_decorator_spec.rb @@ -100,7 +100,10 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do end context 'archived referential' do - before { referential.archived_at = 42.seconds.ago } + before { + referential.ready = true + referential.archived_at = 42.seconds.ago + } context 'no rights' do it 'has only show and calendar actions' do expect_action_link_hrefs.to eq([[object], referential_time_tables_path(object)]) @@ -118,6 +121,19 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do ]) end end + + context 'all rights and same organisation' do + let( :user ){ build_stubbed :allmighty_user, organisation: referential.organisation } + it 'has only default actions' do + expect_action_link_elements.to eq ["Consulter", "Calendriers", "Dupliquer", "Désarchiver"] + expect_action_link_hrefs.to eq([ + [object], + referential_time_tables_path(object), + new_workbench_referential_path(referential.workbench, from: object.id), + unarchive_referential_path(object), + ]) + end + end end end -- cgit v1.2.3 From 7839c6cc052156383d17be27df864f92f40f273c Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 3 May 2018 10:13:34 +0200 Subject: Refs #6920; Fix typo --- app/models/referential.rb | 2 +- spec/models/referential_spec.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/models/referential.rb b/app/models/referential.rb index cabce85d6..792353a73 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -322,7 +322,7 @@ class Referential < ApplicationModel before_create :create_schema after_create :clone_schema, if: :created_from - after_create :active!, unles: :created_from + after_create :active!, unless: :created_from before_destroy :destroy_schema before_destroy :destroy_jobs diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index 720cec48c..2ca0e737d 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -29,6 +29,14 @@ describe Referential, :type => :model do end end + context "creation" do + subject(:referential) { Referential.create name: "test", objectid_format: :netex, organisation: create(:organisation), line_referential: create(:line_referential), stop_area_referential: create(:stop_area_referential) } + it "should activate by default" do + expect(referential).to be_valid + expect(referential.state).to eq :active + end + end + context ".last_operation" do subject(:operation){ referential.last_operation } it "should return nothing" do @@ -110,7 +118,8 @@ describe Referential, :type => :model do context "the scopes" do it "should filter the referentials" do - referential = create :referential, ready: false + referential = create :referential + referential.pending! expect(Referential.pending).to include referential expect(Referential.failed).to_not include referential expect(Referential.active).to_not include referential -- cgit v1.2.3 From fc427e5807f62416fdc93a8c6dda006137f06537 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 4 May 2018 09:03:12 +0200 Subject: Refs #6920; Fix specs --- spec/controllers/statuses_controller_spec.rb | 2 +- spec/factories/referentials.rb | 7 +++++++ spec/features/workbenches/workbenches_show_spec.rb | 1 + spec/models/import/netex_import_spec.rb | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb index 8a6db8e28..65b338888 100644 --- a/spec/controllers/statuses_controller_spec.rb +++ b/spec/controllers/statuses_controller_spec.rb @@ -31,7 +31,7 @@ RSpec.describe StatusesController, :type => :controller do context "with a blocked object" do before do - create :referential, created_at: 5.hours.ago, ready: false + r = create :referential, created_at: 5.hours.ago, status: :pending create :import create :compliance_check_set request diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb index 0276a47be..bbaa7c313 100644 --- a/spec/factories/referentials.rb +++ b/spec/factories/referentials.rb @@ -9,6 +9,13 @@ FactoryGirl.define do time_zone "Europe/Paris" ready { true } objectid_format "stif_netex" + transient do + status :active + end + + after(:create) do |referential, evaluator| + referential.send "#{evaluator.status}!" + end factory :workbench_referential do association :workbench diff --git a/spec/features/workbenches/workbenches_show_spec.rb b/spec/features/workbenches/workbenches_show_spec.rb index 427b526cf..e892f00e7 100644 --- a/spec/features/workbenches/workbenches_show_spec.rb +++ b/spec/features/workbenches/workbenches_show_spec.rb @@ -74,6 +74,7 @@ RSpec.describe 'Workbenches', type: :feature do organisation: @user.organisation, ready: false ) + pending_referential.pending! visit workbench_path(workbench) diff --git a/spec/models/import/netex_import_spec.rb b/spec/models/import/netex_import_spec.rb index 6424fbfe1..bc3b9f7ed 100644 --- a/spec/models/import/netex_import_spec.rb +++ b/spec/models/import/netex_import_spec.rb @@ -32,7 +32,7 @@ RSpec.describe Import::Netex, type: [:model, :with_commit] do describe "#destroy" do it "must destroy its associated Referential if ready: false" do workbench_import = create(:workbench_import) - referential_ready_false = create(:referential, ready: false) + referential_ready_false = create(:referential, status: :pending) referential_ready_true = create(:referential, ready: true) create( :netex_import, -- cgit v1.2.3