-
Notifications
You must be signed in to change notification settings - Fork 110
Cannot use URL/path helpers in decorators at controller tests from ver. 1.5.0 #126
Copy link
Copy link
Open
Description
If we use URL/path helpers in a decorator, we had to add the following lines to test/test_helper.rb.
require "active_decorator/view_context"
ActiveDecorator::ViewContext.push Rails.application.routes.url_helpersHowever NoMethodError occurs from active_decorator 1.5.0, even if we do so.
reproduction code
At first, we write the following Bash script.
# !/bin/bash
rails _$1_ new $2
cd $2
bundle add active_decorator -v "$3"
rails g scaffold item name
rails db:migrate
rails g decorator item
git add .
git commit -m initial
ruby -0pi -e '$_.sub!(/(?=end)/, " def path = item_path(self)\n")' app/decorators/item_decorator.rb
ruby -0pi -e '$_.sub!(/\z/, %(\nrequire "active_decorator/view_context"\nActiveDecorator::ViewContext.push Rails.application.routes.url_helpers))' test/test_helper.rb
ruby -0pi -e '$_.sub!(/(?=end\n\z)/, %(\n test("path_helper") { assert_nothing_raised{ ActiveDecorator::Decorator.instance.decorate(items(:one)).path } }\n))' test/controllers/items_controller_test.rb
rails test -n path_helper test/controllers/items_controller_test.rbThen run it as follows:
$ ./test.sh 7.2.2.2 test1 1.4.1-> No problem. The test is successfull.
$ ./test.sh 7.2.2.2 test2 1.5.0-> The following exception occurs:
Error:
ItemsControllerTest#test_path_helper:
NoMethodError: undefined method 'item_path' for #<Item:0x000000012c291238>
app/decorators/item_decorator.rb:4:in 'ItemDecorator#path'
test/controllers/items_controller_test.rb:49:in 'block (2 levels) in <class:ItemsControllerTest>'
test/controllers/items_controller_test.rb:49:in 'block in <class:ItemsControllerTest>'
$ ./test.sh 7.2.2.2 test2 1.5.1-> Same as ver. 1.5.0.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels