diff options
| -rw-r--r-- | app/decorators/purchase_window_decorator.rb | 4 | ||||
| -rw-r--r-- | app/views/purchase_windows/edit.html.slim | 7 | ||||
| -rw-r--r-- | app/views/purchase_windows/show.html.slim | 2 | ||||
| -rw-r--r-- | config/breadcrumbs.rb | 2 | ||||
| -rw-r--r-- | config/locales/purchase_windows.en.yml | 6 | ||||
| -rw-r--r-- | config/locales/purchase_windows.fr.yml | 8 | ||||
| -rw-r--r-- | lib/stif/permission_translator.rb | 1 | ||||
| -rw-r--r-- | spec/factories/chouette_purchase_windows.rb | 6 | ||||
| -rw-r--r-- | spec/features/purchase_windows_permission_spec.rb | 55 | 
9 files changed, 76 insertions, 15 deletions
| diff --git a/app/decorators/purchase_window_decorator.rb b/app/decorators/purchase_window_decorator.rb index a2060623e..13bc4d666 100644 --- a/app/decorators/purchase_window_decorator.rb +++ b/app/decorators/purchase_window_decorator.rb @@ -27,8 +27,8 @@ class PurchaseWindowDecorator < Draper::Decorator    def bounding_dates      unless object.date_ranges.empty? -      object.date_ranges.min.begin..object.date_ranges.max.end +      object.date_ranges.map(&:min).min..object.date_ranges.map(&:max).max      end    end -end
\ No newline at end of file +end diff --git a/app/views/purchase_windows/edit.html.slim b/app/views/purchase_windows/edit.html.slim new file mode 100644 index 000000000..6354db853 --- /dev/null +++ b/app/views/purchase_windows/edit.html.slim @@ -0,0 +1,7 @@ +- breadcrumb :purchase_window, @referential, @purchase_window +- page_header_content_for @purchase_window +.page_content +  .container-fluid +    .row +      .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 +        = render 'form' diff --git a/app/views/purchase_windows/show.html.slim b/app/views/purchase_windows/show.html.slim index c039257f9..9f3abb267 100644 --- a/app/views/purchase_windows/show.html.slim +++ b/app/views/purchase_windows/show.html.slim @@ -1,4 +1,4 @@ -- breadcrumb :purchase_window, @purchase_window, @referential +- breadcrumb :purchase_window, @referential, @purchase_window  - page_header_content_for @purchase_window  - content_for :page_header_content do    .row.mb-sm diff --git a/config/breadcrumbs.rb b/config/breadcrumbs.rb index 03a98a513..263fc5f42 100644 --- a/config/breadcrumbs.rb +++ b/config/breadcrumbs.rb @@ -167,7 +167,7 @@ crumb :purchase_windows do |referential|    parent :referential, referential  end -crumb :purchase_window do |purchase_window, referential| +crumb :purchase_window do |referential, purchase_window|    link breadcrumb_name(purchase_window), referential_purchase_window_path(referential, purchase_window)    parent :purchase_windows, referential  end diff --git a/config/locales/purchase_windows.en.yml b/config/locales/purchase_windows.en.yml index 5fa98f08f..5ffed305a 100644 --- a/config/locales/purchase_windows.en.yml +++ b/config/locales/purchase_windows.en.yml @@ -57,8 +57,10 @@ en:            end: End    activerecord:      models: -      one: purchase window -      other: purchase windows +      purchase_window: +        zero: purchase window +        one: purchase window +        other: purchase windows      attributes:        purchase_windows:          name: Name diff --git a/config/locales/purchase_windows.fr.yml b/config/locales/purchase_windows.fr.yml index a7db04432..df5d45d82 100644 --- a/config/locales/purchase_windows.fr.yml +++ b/config/locales/purchase_windows.fr.yml @@ -43,7 +43,7 @@ fr:      create:        title: Ajouter un calendrier commercial      edit: -      title: Editer le calendrier comercial %{name} +      title: Editer le calendrier commercial %{name}      show:        title: Calendrier commercial %{name}    simple_form: @@ -57,8 +57,10 @@ fr:            end: Fin    activerecord:      models: -      one: "calendrier commercial" -      other: "calendriers commerciaux" +      purchase_window: +        zero: "calendrier commercial" +        one: "calendrier commercial" +        other: "calendriers commerciaux"      attributes:        purchase_window:          name: Nom diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb index bb35c2784..4acf42884 100644 --- a/lib/stif/permission_translator.rb +++ b/lib/stif/permission_translator.rb @@ -32,7 +32,6 @@ module Stif          compliance_control_sets          compliance_control_blocks          compliance_check_sets -        purchase_windows        ]      end diff --git a/spec/factories/chouette_purchase_windows.rb b/spec/factories/chouette_purchase_windows.rb index 4d29a8801..2e2faf4d8 100644 --- a/spec/factories/chouette_purchase_windows.rb +++ b/spec/factories/chouette_purchase_windows.rb @@ -2,10 +2,7 @@ FactoryGirl.define do    factory :purchase_window, class: Chouette::PurchaseWindow do      sequence(:name) { |n| "Purchase Window #{n}" }      sequence(:objectid) { |n| "organisation:PurchaseWindow:#{n}:LOC" } -    date_ranges { [generate(:periods)] } - -    association :referential -     +    date_ranges { [generate(:periods)] }        end    sequence :periods do |n| @@ -13,4 +10,3 @@ FactoryGirl.define do      date..(date+1)    end  end - diff --git a/spec/features/purchase_windows_permission_spec.rb b/spec/features/purchase_windows_permission_spec.rb new file mode 100644 index 000000000..e74fb5c17 --- /dev/null +++ b/spec/features/purchase_windows_permission_spec.rb @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +require 'spec_helper' + +describe "PurchaseWindows", :type => :feature do +  login_user + +  let(:purchase_window) { create :purchase_window, referential: first_referential} + +  describe 'permissions' do +    before do +      allow_any_instance_of(PurchaseWindowPolicy).to receive(:create?).and_return permission +      allow_any_instance_of(PurchaseWindowPolicy).to receive(:destroy?).and_return permission +      allow_any_instance_of(PurchaseWindowPolicy).to receive(:update?).and_return permission +      visit path +    end + +    context 'on show view' do +      let( :path ){ referential_purchase_window_path(first_referential, purchase_window) } + +      context 'if present → ' do +        let( :permission ){ true } +        it 'view shows the corresponding buttons' do +          expect(page).to have_content(I18n.t('purchase_windows.actions.edit')) +          expect(page).to have_content(I18n.t('purchase_windows.actions.destroy')) +        end +      end + +      context 'if absent → ' do +        let( :permission ){ false } +        it 'view does not show the corresponding buttons' do +          expect(page).not_to have_content(I18n.t('purchase_windows.actions.edit')) +          expect(page).not_to have_content(I18n.t('purchase_windows.actions.destroy')) +        end +      end +    end + +    context 'on index view' do +      let( :path ){ referential_purchase_windows_path(first_referential) } + +      context 'if present → ' do +        let( :permission ){ true } +        it 'index shows an edit button' do +          expect(page).to have_content(I18n.t('purchase_windows.actions.new')) +        end +      end + +      context 'if absent → ' do +        let( :permission ){ false } +        it 'index does not show any edit button' do +          expect(page).not_to have_content(I18n.t('purchase_windows.actions.new')) +        end +      end +    end +  end +end | 
