diff options
| author | Zog | 2018-01-21 11:59:33 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-21 11:59:33 +0100 | 
| commit | f6f4863740f06f9719f4230de4a28630bddde391 (patch) | |
| tree | 00662e81dbfa99d0cd86f9bb8262ec26f3bfd8fb | |
| parent | 5b1c1be8cd9526b08ff26b5e50ffd228b0a25374 (diff) | |
| download | chouette-core-f6f4863740f06f9719f4230de4a28630bddde391.tar.bz2 | |
Refs 5586; CR #1
| -rw-r--r-- | app/assets/stylesheets/components/_buttons.sass | 2 | ||||
| -rw-r--r-- | app/controllers/lines_controller.rb | 2 | ||||
| -rw-r--r-- | app/decorators/line_decorator.rb | 4 | ||||
| -rw-r--r-- | app/decorators/time_table_decorator.rb | 7 | ||||
| -rw-r--r-- | lib/af83/decorator/link.rb | 4 | ||||
| -rw-r--r-- | lib/af83/enhanced_decorator.rb | 3 | ||||
| -rw-r--r-- | spec/lib/af83/decorator/decorator_spec.rb | 2 | ||||
| -rw-r--r-- | spec/views/referentials/show.html.erb_spec.rb | 45 | 
8 files changed, 54 insertions, 15 deletions
| diff --git a/app/assets/stylesheets/components/_buttons.sass b/app/assets/stylesheets/components/_buttons.sass index 9a99ba8bc..a7010ae09 100644 --- a/app/assets/stylesheets/components/_buttons.sass +++ b/app/assets/stylesheets/components/_buttons.sass @@ -150,7 +150,7 @@ table, .table              white-space: nowrap              padding: 5px 15px              font-weight: normal -            line-height: 1.42857 +            line-height: $line-height              display: block              font-size: 14px              &:hover diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index 22578187f..27a9bf9be 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -70,8 +70,6 @@ class LinesController < ChouetteController      end    end -  helper_method :decorated_collection -    protected    def filtered_lines_maps diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb index d8ffdad69..7d247a99c 100644 --- a/app/decorators/line_decorator.rb +++ b/app/decorators/line_decorator.rb @@ -17,12 +17,12 @@ class LineDecorator < AF83::Decorator        l.href   { [context[:line_referential], object] }      end -    instance_decorator.action_link do |l| +    instance_decorator.action_link secondary: :show do |l|        l.content t('lines.actions.show_network')        l.href   { [context[:line_referential], object.network] }      end -    instance_decorator.action_link do |l| +    instance_decorator.action_link secondary: :show do |l|        l.content  t('lines.actions.show_company')        l.href     { [context[:line_referential], object.company] }        l.disabled { object.company.nil? } diff --git a/app/decorators/time_table_decorator.rb b/app/decorators/time_table_decorator.rb index d3aef4550..9a56fc2ee 100644 --- a/app/decorators/time_table_decorator.rb +++ b/app/decorators/time_table_decorator.rb @@ -46,12 +46,7 @@ class TimeTableDecorator < AF83::Decorator      end      instance_decorator.destroy_action_link  do |l| -      l.href do -        h.duplicate_referential_time_table_path( -          context[:referential], -          object -        ) -      end +      l.href { h.referential_time_table_path(context[:referential], object) }        l.data {{ confirm: h.t('time_tables.actions.destroy_confirm') }}      end    end diff --git a/lib/af83/decorator/link.rb b/lib/af83/decorator/link.rb index e7ab90d55..83d40eba8 100644 --- a/lib/af83/decorator/link.rb +++ b/lib/af83/decorator/link.rb @@ -136,9 +136,9 @@ class AF83::Decorator::Link    def to_html      if block_given? -      link = Link.new(@options) +      link = AF83::Decorator::Link.new(@options).bind_to_context(context, @action)        yield link -      return link.bind_to_context(context, @action).to_html +      return link.to_html      end      if type&.to_sym == :button        HTMLElement.new( diff --git a/lib/af83/enhanced_decorator.rb b/lib/af83/enhanced_decorator.rb index ee18686f4..aa9620dba 100644 --- a/lib/af83/enhanced_decorator.rb +++ b/lib/af83/enhanced_decorator.rb @@ -45,9 +45,10 @@ module AF83::EnhancedDecorator      def edit_action_link args={}, &block        opts = {          primary: %i(show index), +        policy: :edit,          before_block: -> (l){            l.content { h.t('actions.edit') } -          l.href { [object] } +          l.href { [:edit, object] }          }        }        action_link opts.update(args), &block diff --git a/spec/lib/af83/decorator/decorator_spec.rb b/spec/lib/af83/decorator/decorator_spec.rb index 32c76c22f..61a849b9d 100644 --- a/spec/lib/af83/decorator/decorator_spec.rb +++ b/spec/lib/af83/decorator/decorator_spec.rb @@ -239,7 +239,7 @@ RSpec.describe AF83::Decorator, type: :decorator do              klass            end -          it "should return links in the sequence they were defined" do +          it "should return links in the correct sequence" do              links = decorated.action_links              expect(links.size).to eq 2              instance_exec links.first, link_options_2, &link_should_match_options diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb index f1fa7188a..a77d348de 100644 --- a/spec/views/referentials/show.html.erb_spec.rb +++ b/spec/views/referentials/show.html.erb_spec.rb @@ -1,4 +1,49 @@  require 'spec_helper'  describe "referentials/show", type: :view do + +  let!(:referential) do +    referential = create(:referential, organisation: current_organisation) +    assign :referential, referential.decorate(context: { +      current_organisation: referential.organisation +    }) +  end +  let(:permissions){ [] } +  let(:current_organisation) { organisation } +  let(:current_offer_workbench) { create :workbench, organisation: current_organisation} +  let(:readonly){ false } + +  before :each do +    assign :reflines, [] +    allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench) +    allow(view).to receive(:current_organisation).and_return(current_organisation) +    allow(view).to receive(:current_user).and_return(current_user) + +    allow(view).to receive(:resource).and_return(referential) +    allow(view).to receive(:has_feature?).and_return(true) +    allow(view).to receive(:user_signed_in?).and_return true +    controller.request.path_parameters[:id] = referential.id +    allow(view).to receive(:params).and_return({action: :show}) + +    allow(referential).to receive(:referential_read_only?){ readonly } +    render template: "referentials/show", layout: "layouts/application" +  end + +  it "should not present edit button" do +    expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]") +  end + +  with_permission "referentials.update" do +    it "should present edit button" do +      expect(rendered).to have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]") +    end + +    context "with a readonly referential" do +      let(:readonly){ true } +      it "should not present edit button" do +        expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]") +      end +    end +  end +  end | 
