diff options
| author | Robert | 2017-12-12 16:06:48 +0100 | 
|---|---|---|
| committer | Robert | 2017-12-12 17:36:42 +0100 | 
| commit | f4c5a5a986d2e0e45b33014564eeb6e4e09b66f7 (patch) | |
| tree | 3fa2b7599f874bbbafd808444a88cfadf048e64e | |
| parent | 4a020f3e4ad795a780617febbc364a6f270d310d (diff) | |
| download | chouette-core-f4c5a5a986d2e0e45b33014564eeb6e4e09b66f7.tar.bz2 | |
Refs: #5206@2.5h; Debugging  helper and specing its behavior
  - Debugged obvious bugs in the helper
  - Dead Code Elimination in the helper
  - Specs with color diff
| -rw-r--r-- | app/helpers/multiple_selection_toolbox_helper.rb | 11 | ||||
| -rw-r--r-- | app/views/workbenches/show.html.slim | 2 | ||||
| -rw-r--r-- | spec/db/schema_spec.rb | 8 | ||||
| -rw-r--r-- | spec/helpers/multiple_selection_toolbox_helper_spec.rb | 25 | ||||
| -rw-r--r-- | spec/helpers/table_builder_helper_spec.rb | 8 | ||||
| -rw-r--r-- | spec/support/text.rb | 18 | 
6 files changed, 51 insertions, 21 deletions
| diff --git a/app/helpers/multiple_selection_toolbox_helper.rb b/app/helpers/multiple_selection_toolbox_helper.rb index e0a1d2dd4..8e23aef7d 100644 --- a/app/helpers/multiple_selection_toolbox_helper.rb +++ b/app/helpers/multiple_selection_toolbox_helper.rb @@ -2,17 +2,12 @@ module MultipleSelectionToolboxHelper    # Box of links that floats at the bottom right of the page    # c.f. https://projects.af83.io/issues/5206    # #5206 method too long -  def multiple_selection_toolbox(actions, collection_name:) +  def multiple_selection_toolbox(workbench_id, *actions, collection_name:)      links = content_tag :ul do -      # #5206 `if params[:controller]` mieux passer comme parametre si besoin -      delete_path = nil +      delete_path = referentials_workbench_path workbench_id -      if params[:controller] = 'workbenches' -        delete_path = referentials_workbench_path -      end - -      actions.map do |action| +      actions.flatten.map do |action|          if action == :delete            action_link = link_to(              '#', diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index af312fc08..bc5c35f86 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -61,7 +61,7 @@                links: [:show, :edit],                cls: 'table has-filter has-search' -            = multiple_selection_toolbox([:delete], collection_name: 'referentials') +            = multiple_selection_toolbox(@workbench.id, :delete, collection_name: 'referentials')            = new_pagination @wbench_refs, 'pull-right' diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index 585636124..705a9e2f6 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -37,13 +37,7 @@ RSpec::Matchers.define :use_bigint_keys do    failure_message do |filename|      <<-EOS  expected #{filename.inspect} to use bigint keys -Diff: #{diff} +Diff: #{colorized_diff @original, @expected}      EOS    end - -  def diff -    RSpec::Support::Differ.new( -      color: RSpec::Matchers.configuration.color? -    ).diff_as_string(@expected, @original) -  end  end diff --git a/spec/helpers/multiple_selection_toolbox_helper_spec.rb b/spec/helpers/multiple_selection_toolbox_helper_spec.rb new file mode 100644 index 000000000..e30fb054a --- /dev/null +++ b/spec/helpers/multiple_selection_toolbox_helper_spec.rb @@ -0,0 +1,25 @@ +RSpec.describe MultipleSelectionToolboxHelper, type: :helper do + +  let( :workbench_id ){ random_int } + +  let( :expected_html ) do <<-EOHTML.chomp +<div class="select_toolbox noselect" id="selected-referentials-action-box"> +    <ul> +        <li class="st_action"><a data-path="/workbenches/#{workbench_id}/referentials" data-confirm="Etes-vous sûr(e) de vouloir effectuer cette action ?" title="Supprimer" rel="nofollow" data-method="delete" href="#"><span class="fa fa-trash"></span></a></li> +    </ul> +    <span class="info-msg"><span>0</span> élément(s) sélectionné(s)</span></div> +  EOHTML +  end + +  context 'rendering' do  + +    it 'the expected output' do +      output = beautify_html(helper. +        multiple_selection_toolbox(workbench_id, :delete, collection_name: 'referentials')) + +      expect(output).to eq(expected_html), colorized_diff(expected_html, output) +    end +     +  end +   +end diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 3b0a18379..ce3c98dc8 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -1,5 +1,3 @@ -require 'htmlbeautifier' -  module TableBuilderHelper    include Pundit  end @@ -152,7 +150,7 @@ describe TableBuilderHelper, type: :helper do          cls: 'table has-filter has-search'        ) -      beautified_html = HtmlBeautifier.beautify(html_str, indent: '    ') +      beautified_html = beautify_html(html_str, indent: 4)        expect(beautified_html).to eq(expected.chomp)      end @@ -264,7 +262,7 @@ describe TableBuilderHelper, type: :helper do          cls: 'table has-search'        ) -      beautified_html = HtmlBeautifier.beautify(html_str, indent: '    ') +      beautified_html = beautify_html(html_str, indent: 4)        expect(beautified_html).to eq(expected.chomp)      end @@ -377,7 +375,7 @@ describe TableBuilderHelper, type: :helper do          cls: 'table has-search'        ) -      beautified_html = HtmlBeautifier.beautify(html_str, indent: '    ') +      beautified_html = beautify_html(html_str, indent: 4)        expect(beautified_html).to eq(expected.chomp)      end diff --git a/spec/support/text.rb b/spec/support/text.rb new file mode 100644 index 000000000..1fe02436d --- /dev/null +++ b/spec/support/text.rb @@ -0,0 +1,18 @@ +require 'htmlbeautifier' + +module Support::Text +  +  def beautify_html html, indent: 4   +    HtmlBeautifier.beautify(html, indent: ' ' * indent) +  end + +  def colorized_diff(actual, expected) +    RSpec::Support::Differ.new( +      color: RSpec::Matchers.configuration.color? +    ).diff_as_string(expected, actual) +  end  +end + +RSpec.configure do | config | +  config.include Support::Text +end | 
