aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlatka Pavisic2017-01-27 12:58:45 +0100
committerVlatka Pavisic2017-01-27 12:58:45 +0100
commitc6e66eae73984798ceea041c7478ba74c5599f3f (patch)
tree553ce19c55d03be454b8d0bd19b033f7fc0e1b63
parent4fdc30f46f8a296dcd15b827a99f8c7a09338d50 (diff)
downloadchouette-core-c6e66eae73984798ceea041c7478ba74c5599f3f.tar.bz2
Refs #2469 : Referential#ready
-rw-r--r--app/controllers/referentials_controller.rb1
-rw-r--r--app/controllers/workbenches_controller.rb2
-rw-r--r--app/models/referential.rb2
-rw-r--r--app/models/referential_cloning.rb3
-rw-r--r--db/migrate/20170127092058_add_ready_to_referentials.rb5
-rw-r--r--db/schema.rb3
-rw-r--r--spec/features/workbenches_spec.rb17
7 files changed, 31 insertions, 2 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index 23eb6263d..6957479df 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -105,6 +105,7 @@ class ReferentialsController < BreadcrumbController
def create_resource(referential)
referential.organisation = current_organisation unless referential.created_from
+ referential.ready = true
super
end
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb
index b2bf5eab8..4d7bec1dc 100644
--- a/app/controllers/workbenches_controller.rb
+++ b/app/controllers/workbenches_controller.rb
@@ -4,7 +4,7 @@ class WorkbenchesController < BreadcrumbController
respond_to :html, :only => [:show]
def show
- @wbench_refs = Workbench.find(params[:id]).referentials.paginate(page: params[:page], per_page: 20)
+ @wbench_refs = Workbench.find(params[:id]).referentials.ready.paginate(page: params[:page], per_page: 20)
show! do
build_breadcrumb :show
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 7d0b0cf93..ad82f40dc 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -43,6 +43,8 @@ class Referential < ActiveRecord::Base
has_many :stop_areas, through: :stop_area_referential
belongs_to :workbench
+ scope :ready, -> { where(ready: true) }
+
def lines
if metadatas.blank?
workbench ? workbench.lines : associated_lines
diff --git a/app/models/referential_cloning.rb b/app/models/referential_cloning.rb
index 9bf824ac5..2f34093e2 100644
--- a/app/models/referential_cloning.rb
+++ b/app/models/referential_cloning.rb
@@ -20,6 +20,9 @@ class ReferentialCloning < ActiveRecord::Base
end
event :successful, after: :update_ended_at do
+ after do
+ target_referential.update_attribute(:ready, true)
+ end
transitions :from => [:pending, :failed], :to => :successful
end
diff --git a/db/migrate/20170127092058_add_ready_to_referentials.rb b/db/migrate/20170127092058_add_ready_to_referentials.rb
new file mode 100644
index 000000000..0b7638977
--- /dev/null
+++ b/db/migrate/20170127092058_add_ready_to_referentials.rb
@@ -0,0 +1,5 @@
+class AddReadyToReferentials < ActiveRecord::Migration
+ def change
+ add_column :referentials, :ready, :boolean, default: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index babd35e3d..69ffd69e5 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170123131243) do
+ActiveRecord::Schema.define(version: 20170127092058) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -446,6 +446,7 @@ ActiveRecord::Schema.define(version: 20170123131243) do
t.integer "workbench_id"
t.datetime "archived_at"
t.integer "created_from_id"
+ t.boolean "ready", default: false
end
add_index "referentials", ["created_from_id"], :name => "index_referentials_on_created_from_id"
diff --git a/spec/features/workbenches_spec.rb b/spec/features/workbenches_spec.rb
new file mode 100644
index 000000000..1ff39e1be
--- /dev/null
+++ b/spec/features/workbenches_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'Workbenches', type: :feature do
+ login_user
+
+ let!(:workbench) { create :workbench }
+ let!(:ready_referential) { create(:referential, workbench: workbench, ready: true) }
+ let!(:unready_referential) { create(:referential, workbench: workbench) }
+
+ describe 'show' do
+ it 'shows ready referentials belonging to that workbench' do
+ visit workbench_path(workbench)
+ expect(page).to have_content(ready_referential.name)
+ expect(page).not_to have_content(unready_referential.name)
+ end
+ end
+end