diff options
| author | Zog | 2018-01-17 09:43:37 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-17 09:43:37 +0100 | 
| commit | a958ae52a763e09574c22625c2cd3481c2b1bb6c (patch) | |
| tree | 690e08248d7a9f53ef69b713039dd8be76232e31 | |
| parent | 33b0cb432076fbb6e6904aeeff4e13c5003ed53f (diff) | |
| download | chouette-core-a958ae52a763e09574c22625c2cd3481c2b1bb6c.tar.bz2 | |
Refs #5586; Add a `feature` option on the `action_links`
| -rw-r--r-- | lib/af83/decorator.rb | 5 | ||||
| -rw-r--r-- | lib/af83/enhanced_decorator.rb | 7 | ||||
| -rw-r--r-- | spec/lib/af83/decorator/decorator_spec.rb | 32 | 
3 files changed, 43 insertions, 1 deletions
| diff --git a/lib/af83/decorator.rb b/lib/af83/decorator.rb index 80958fa02..d2e049857 100644 --- a/lib/af83/decorator.rb +++ b/lib/af83/decorator.rb @@ -196,6 +196,7 @@ class AF83::Decorator < ModelDecorator        end        enabled = enabled && check_policy(@options[:_policy]) if @options[:_policy].present? +      enabled = enabled && check_feature(@options[:_feature]) if @options[:_feature].present?        enabled      end @@ -204,6 +205,10 @@ class AF83::Decorator < ModelDecorator        @context.check_policy policy      end +    def check_feature(feature) +      @context.check_feature feature +    end +      def errors        "Missing attributes: #{@missing_attributes.to_sentence}"      end diff --git a/lib/af83/enhanced_decorator.rb b/lib/af83/enhanced_decorator.rb index 91a377f8c..4ade0980b 100644 --- a/lib/af83/enhanced_decorator.rb +++ b/lib/af83/enhanced_decorator.rb @@ -28,7 +28,7 @@ module AF83::EnhancedDecorator      def parse_options args        options = {} -      %i(weight primary secondary footer on action actions policy if groups group).each do |k| +      %i(weight primary secondary footer on action actions policy feature if groups group).each do |k|          options[k] = args.delete(k) if args.has_key?(k)        end        link_options = args.dup @@ -54,6 +54,7 @@ module AF83::EnhancedDecorator        link_options[:_if] = options.delete(:if)        link_options[:_policy] = options.delete(:policy) +      link_options[:_feature] = options.delete(:feature)        [options, link_options]      end    end @@ -79,4 +80,8 @@ module AF83::EnhancedDecorator      method = "#{policy}?"      h.policy(_object).send(method)    end + +  def check_feature feature +    h.has_feature? feature +  end  end diff --git a/spec/lib/af83/decorator/decorator_spec.rb b/spec/lib/af83/decorator/decorator_spec.rb index 789813063..32c76c22f 100644 --- a/spec/lib/af83/decorator/decorator_spec.rb +++ b/spec/lib/af83/decorator/decorator_spec.rb @@ -308,6 +308,38 @@ RSpec.describe AF83::Decorator, type: :decorator do            end          end +        context "with a feature" do +          let(:decorator) do +            klass = Class.new(AF83::Decorator) +            klass.with_instance_decorator do |instance_decorator| +              instance_decorator.action_link href: "foo", content: "foo", feature: :foo +            end +            klass +          end + +          context "when the feature is not present" do +            before(:each) do +              Draper::HelperProxy.any_instance.stub(:has_feature?){false} +            end + +            it "should not return the link" do +              links = decorated.action_links(:show) +              expect(links.size).to eq 0 +            end +          end + +          context "when the feature is present" do +            before(:each) do +              Draper::HelperProxy.any_instance.stub(:has_feature?){true} +            end + +            it "should not return the link" do +              links = decorated.action_links(:show) +              expect(links.size).to eq 1 +            end +          end +        end +          context "with a condition" do            context "set with 'with_condition'" do              context "as a value" do | 
