GithubHelp home page GithubHelp logo

Comments (11)

jcasimir avatar jcasimir commented on July 20, 2024

Julien,

Interesting, I don't have an easy answer for you. I'll try some experiments and see if anyone comes up with a suggestion/solution in the meantime.

from draper.

jperville avatar jperville commented on July 20, 2024

Hello,

I finally decided to hide my initialization code in spec_helper.rb.

# Used to initialize decorator specs. Called from a 'before' block.
def initialize_controller_view_context_for_draper
  c = ApplicationController.new
  c.request = ActionDispatch::TestRequest.new
  c.set_current_view_context
end

Then I use in each spec that renders a view in the before hook:

describe UserDecorator do
  before { initialize_controller_view_context_for_draper }
end

This is now manageable but still not very satisfying.
I will keep watching this thread.

Thank you very much.

Julien

from draper.

voldy avatar voldy commented on July 20, 2024

Hello,
I faced with the same problem when tried to spec url_for.

@jperville: thank you for your solution. I have modified it a little and placed to spec_helper.rb:

module Draper::ViewContextFilter
  alias :original_set_current_view_context :set_current_view_context

  def set_current_view_context
    controller = ApplicationController.new
    controller.request = ActionDispatch::TestRequest.new
    controller.original_set_current_view_context
  end
end

Then it is possible to use Draper's standard call:

before { ApplicationController.new.set_current_view_context }

from draper.

andreacfm avatar andreacfm commented on July 20, 2024

Hi I am using @jperville workaround.
Will this be fixed or does exists a better way?

from draper.

tooky avatar tooky commented on July 20, 2024

Using the workaround makes url helpers work within the decorator, but you can't reference the helpers within the spec!

from draper.

jcasimir avatar jcasimir commented on July 20, 2024

Working on this...

from draper.

henrik avatar henrik commented on July 20, 2024

@tooky To reference the helpers within the spec, do e.g.

describe SomeDecorator, "#foo" do
  include Rails.application.routes.url_helpers
  it { blah.should == root_path }
end

from draper.

tooky avatar tooky commented on July 20, 2024

@henrik thanks! I think I must have had this in and removed it for some reason when adding the workaround!

from draper.

steveklabnik avatar steveklabnik commented on July 20, 2024

So! This issue is fixed. Actually. Here's the solution:

  1. If you have before { ApplicationController.new.set_current_view_context } in your spec, delete it. Older versions of Draper generated this line, but no longer.
  2. Update your copy of Draper. 58e9893 introduced stubbing out the request properly. It's in both 0.12.1 and 0.13.0.

This fixed it on my test application, so I'm closing. If it doesn't on yours, well........ that's bad. We can re-open and figure it out.

from draper.

jperville avatar jperville commented on July 20, 2024

Thank you so much for fixing the issue.
Julien

from draper.

steveklabnik avatar steveklabnik commented on July 20, 2024

No problem. @cheald did all the work. ;)

from draper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.