aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-09-05 14:26:20 +0200
committercedricnjanga2017-09-05 14:36:47 +0200
commitdf7552799d16d5686e389e484a00e0a7e8fb4e1d (patch)
treea8fb56d2e41aef844cdfb5790417eaba07430fb8
parent70e8e93b0ebf4596c0ffd64620415db2450f4595 (diff)
downloadchouette-core-df7552799d16d5686e389e484a00e0a7e8fb4e1d.tar.bz2
Referential#new_from :
Added params to certains paths to have the workbench_id in it. The goal is to have the current workbench_id to assign it when do a Referential#new_from Then I finished the use of the functional scope to avoid potential errors I skipped some tests that hve a #TODO so we can easily find them
-rw-r--r--app/controllers/application_controller.rb3
-rw-r--r--app/controllers/referentials_controller.rb3
-rw-r--r--app/controllers/workbenches_controller.rb9
-rw-r--r--app/decorators/referential_decorator.rb2
-rw-r--r--app/views/workbenches/index.html.slim2
-rw-r--r--app/views/workbenches/show.html.slim2
-rw-r--r--spec/features/workbenches_spec.rb30
-rw-r--r--spec/support/devise.rb4
8 files changed, 34 insertions, 21 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 47b54039c..cc1c30703 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -34,7 +34,8 @@ class ApplicationController < ActionController::Base
helper_method :current_organisation
def current_functional_scope
- JSON.parse(current_organisation.sso_attributes["functional_scope"]) if current_organisation
+ functional_scope = current_organisation.sso_attributes.try(:[], "functional_scope") if current_organisation
+ JSON.parse(functional_scope) if functional_scope
end
helper_method :current_functional_scope
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index a6dfaf2b6..bd0544a74 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -10,7 +10,6 @@ class ReferentialsController < BreadcrumbController
if params[:from]
source_referential = Referential.find(params[:from])
@referential = Referential.new_from(source_referential, current_functional_scope)
- @referential.workbench_id = current_organisation.workbenches.first.id
end
new! do
@@ -26,7 +25,7 @@ class ReferentialsController < BreadcrumbController
def show
resource.switch
show! do |format|
- @referential = @referential.decorate
+ @referential = @referential.decorate(context: { workbench_id: params[:workbench_id] } )
@reflines = lines_collection.paginate(page: params[:page], per_page: 10)
@reflines = ModelDecorator.decorate(
@reflines,
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb
index 19af28a98..bae3fcff2 100644
--- a/app/controllers/workbenches_controller.rb
+++ b/app/controllers/workbenches_controller.rb
@@ -20,8 +20,13 @@ class WorkbenchesController < BreadcrumbController
@q_for_form = scope.ransack(params[:q])
@q_for_result = scope.ransack(ransack_params)
@wbench_refs = sort_result(@q_for_result.result).paginate(page: params[:page], per_page: 30)
- @wbench_refs = ModelDecorator.decorate(@wbench_refs, with: ReferentialDecorator)
-
+ @wbench_refs = ModelDecorator.decorate(
+ @wbench_refs,
+ with: ReferentialDecorator,
+ context: {
+ workbench_id: params[:id]
+ }
+ )
show! do
build_breadcrumb :show
end
diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb
index ccb47a654..4e9c242fd 100644
--- a/app/decorators/referential_decorator.rb
+++ b/app/decorators/referential_decorator.rb
@@ -13,7 +13,7 @@ class ReferentialDecorator < Draper::Decorator
if policy.clone?
links << Link.new(
content: h.t('actions.clone'),
- href: h.new_referential_path(from: object.id)
+ href: h.new_referential_path(from: object.id, workbench_id: context[:workbench_id])
)
end
if policy.archive?
diff --git a/app/views/workbenches/index.html.slim b/app/views/workbenches/index.html.slim
index d57f579ff..eece51bca 100644
--- a/app/views/workbenches/index.html.slim
+++ b/app/views/workbenches/index.html.slim
@@ -41,7 +41,7 @@
- if @referentials.any?
.list-group
- @referentials.each_with_index do |referential, i|
- = link_to referential.name, referential_path(referential), class: 'list-group-item' if i < 6
+ = link_to referential.name, referential_path(referential, workbench_id: referential.workbench_id), class: 'list-group-item' if i < 6
- else
.panel-body
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index bb54f07cb..80451ec34 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -29,7 +29,7 @@
key: :name, \
attribute: 'name', \
link_to: lambda do |referential| \
- referential_path(referential) \
+ referential_path(referential, workbench_id: referential.workbench_id) \
end \
), \
TableBuilderHelper::Column.new( \
diff --git a/spec/features/workbenches_spec.rb b/spec/features/workbenches_spec.rb
index d1ba0046f..5061e5c5b 100644
--- a/spec/features/workbenches_spec.rb
+++ b/spec/features/workbenches_spec.rb
@@ -169,7 +169,7 @@ describe 'Workbenches', type: :feature do
end
context 'user does not have the permission to create referentials' do
- xit 'does not show the clone link for referential' do
+ it 'does not show the clone link for referential' do
@user.update_attribute(:permissions, [])
visit referential_path(referential)
expect(page).not_to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbench.id))
@@ -178,16 +178,24 @@ describe 'Workbenches', type: :feature do
end
describe 'create new Referential' do
- xit "create a new Referential with a specifed line and period" do
- referential.destroy
-
- visit workbench_path(workbench)
- click_link I18n.t('actions.add')
- fill_in "referential[name]", with: "Referential to test creation"
- select workbench.lines.first.id, from: 'referential[metadatas_attributes][0][lines][]'
-
- click_button "Valider"
- expect(page).to have_css("h1", text: "Referential to test creation")
+ #TODO Manage functional_scope
+ it "create a new Referential with a specifed line and period" do
+ skip: "The functional scope for the Line collection causes problems" do
+ functional_scope = JSON.generate(Chouette::Line.all.map(&:objectid))
+ lines = Chouette::Line.where(objectid: functional_scope)
+
+ @user.organisation.update_attribute(:sso_attributes, { functional_scope: functional_scope } )
+ ref_metadata.update_attribute(:line_ids, lines.map(&:id))
+
+ referential.destroy
+ visit workbench_path(workbench)
+ click_link I18n.t('actions.add')
+ fill_in "referential[name]", with: "Referential to test creation"
+ select ref_metadata.line_ids.first, from: 'referential[metadatas_attributes][0][lines][]'
+
+ click_button "Valider"
+ expect(page).to have_css("h1", text: "Referential to test creation")
+ end
end
end
end
diff --git a/spec/support/devise.rb b/spec/support/devise.rb
index 46249fef2..c9fd1b8e5 100644
--- a/spec/support/devise.rb
+++ b/spec/support/devise.rb
@@ -3,10 +3,10 @@ module DeviseRequestHelper
def login_user
organisation = Organisation.where(:code => "first").first_or_create(attributes_for(:organisation))
- @user ||=
+ @user ||=
create(:user,
:organisation => organisation,
- :permissions => Support::Permissions.all_permissions)
+ :permissions => Support::Permissions.all_permissions)
login_as @user, :scope => :user
# post_via_redirect user_session_path, 'user[email]' => @user.email, 'user[password]' => @user.password