diff options
| author | Teddy Wing | 2017-07-06 10:51:00 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-07-06 12:30:59 +0200 | 
| commit | 74e94da83d6ea64dcb1e70e69c2fef046453e4a1 (patch) | |
| tree | f7c7a55f5499e1a58c0aa6cdd0259ca827d02f4a | |
| parent | 8a2818897911e5b33af6849e2ea648ae6e014eef (diff) | |
| download | chouette-core-74e94da83d6ea64dcb1e70e69c2fef046453e4a1.tar.bz2 | |
TableBuilderHelper: Fix specs which mock `current_referential`
These two specs were failing because of the line:
    current_referential ||= nil
which would set `current_referential` to `nil` even after updating the
object being stubbed to `helper`.
Change the specs to stub the method on the correct object now that
`TableBuilderHelper::URL` doesn't depend on `current_referential`.
Update the faulty line in question to not clobber `current_referential`,
but still give us the `nil` value we were looking for when the helper
method isn't defined.
Refs #3479
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 8 | ||||
| -rw-r--r-- | spec/helpers/table_builder_helper_spec.rb | 4 | 
2 files changed, 6 insertions, 6 deletions
| diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 1ddd629f8..e1b8b406d 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -104,9 +104,9 @@ module TableBuilderHelper    end    def tbody(collection, columns, selectable, links) -    # Certain controllers don't define a `#current_referential`. If the method -    # is unavailable, give it a default value to avoid a `NoMethodError`. -    current_referential ||= nil +    # Certain controllers don't define a `#current_referential`. In these +    # cases, avoid a `NoMethodError`. +    referential = current_referential if respond_to?(:current_referential)      content_tag :tbody do        collection.map do |item| @@ -128,7 +128,7 @@ module TableBuilderHelper                # Build a link to the `item`                polymorph_url = URL.polymorphic_url_parts(                  item, -                current_referential +                referential                )                bcont << content_tag(:td, link_to(value, polymorph_url), title: 'Voir')              else diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 67980fc2c..d90c14204 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -176,7 +176,7 @@ describe TableBuilderHelper, type: :helper do          referential: referential        )        allow(helper).to receive(:current_user).and_return(user_context) -      allow(TableBuilderHelper::URL).to receive(:current_referential) +      allow(helper).to receive(:current_referential)          .and_return(referential)        companies = [company] @@ -284,7 +284,7 @@ describe TableBuilderHelper, type: :helper do          referential: referential        )        allow(helper).to receive(:current_user).and_return(user_context) -      allow(TableBuilderHelper::URL).to receive(:current_referential) +      allow(helper).to receive(:current_referential)          .and_return(referential)        companies = [company] | 
