aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2018-05-04 09:55:12 +0200
committerGitHub2018-05-04 09:55:12 +0200
commit4438611e99c12faefdc73ff6cbd966951bc6dd1b (patch)
treeaaa19e2a194063c222c0e26c7a16877dcbecdf7c
parentfc71f67eb75f956aa2c3e1aae85e99b5b82bc0a3 (diff)
parentfc427e5807f62416fdc93a8c6dda006137f06537 (diff)
downloadchouette-core-4438611e99c12faefdc73ff6cbd966951bc6dd1b.tar.bz2
Merge pull request #549 from af83/6920-activate-newly-created-referentials
6920 activate newly created referentials
-rw-r--r--app/decorators/referential_decorator.rb2
-rw-r--r--app/models/referential.rb1
-rw-r--r--spec/controllers/statuses_controller_spec.rb2
-rw-r--r--spec/decorators/referential_decorator_spec.rb18
-rw-r--r--spec/factories/referentials.rb7
-rw-r--r--spec/features/workbenches/workbenches_show_spec.rb1
-rw-r--r--spec/models/import/netex_import_spec.rb2
-rw-r--r--spec/models/referential_spec.rb11
8 files changed, 39 insertions, 5 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/app/models/referential.rb b/app/models/referential.rb
index b4f64fad1..792353a73 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!, unless: :created_from
before_destroy :destroy_schema
before_destroy :destroy_jobs
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/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
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,
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