I am a total Groovy newbie. I saw the following code here.
def beforeInterceptor = [action:this.&auth,except:'login']
How would I expand this to also include a second exception, say, if the action was 'login2'?
Wow, would have expected a quick answer on this!
Well, found my own answer: you can't have more than one exception with except.
See the feature request here.
Instead, they recommend creating a Filter. See here.
Related
I'm reading this question, where it says, that the calls
something {|i| i.foo }
something(&:foo)
are equivalent.
Now I was trying to refactor my model named AdminUser according to this pattern and replaced
after_create { |admin| admin.send_reset_password_instructions }
with
after_create(&:send_reset_password_instructions)
, but when I'm running my migration, which contains the lines
def migrate(direction)
super
# Create a default user
AdminUser.create!(email: 'a#b.de', password: 'very_clever', password_confirmation: 'very_clever') if direction == :up
end
it gives me the error
ArgumentError: no receiver given
pointing to the line AdminUser.create!....
Can anyone tell me what goes wrong here?
I know this is an older question, but it interested me quite a bit causing me to do some research of my own. I don't have a corrected code answer for you, but in looking around I believe this post what happened when pass a method to iterator method is very closely related and will most likely answer your question of "what's going wrong here?"
Basically because you're now passing it a proc with the refactored code it's expecting a specific argument that your AdminUser is no longer passing it and causing the error of it not having a receiver.
That being said, I'm sure you have your reasons of setting up your code the way you do, but based on the implied idea of what you're doing and the context I would agree with #photoionized with using
after_create :send_reset_password_instructions as it's clear, concise and (most likely) has your desired outcome.
In thumbs_up documentation there is Shorthand Syntax section.
...
voter.vote(voteable, vote)
...
What's a vote that is coming as a second parameter there? How could I define it or where from I could get it?
vote is a option hash.
voter.vote(voteable, direction: :down) would be a downvote.
&
voter.vote(voteable, direction: :up) would be a upvote. `
EDIT:
The documentation seems to have some differences with the code :P
It seems the documentation for vote was incorrect and I've submitted a PR to fix this https://github.com/bouchard/thumbs_up/pull/104
vote takes a second argument which is a hash of options. The direction key of the hash is a required key which needs to have a value of :up or :down.
You can find it in the source code. It's a Hash of options.
This method seems to be the base utility function for the various vote helpers. You should probably use vote_for.
I'm trying to use some embedded ruby in the subject line of an email coming from ActionMailer but keep getting different errors.
I couldn't find any documentation on the proper syntax. Any resources to fix this line of code?
mail(to: #user.email, subject: "Your Reservation Confirmation for" + #restaurant.name)
I've passed in all of the variables fine. I just need to see how I can combine text and these inputs.
Thanks
There are two common ways to it:
First:(regarding rep)
"...Confirmation for" + #restaurant.name.to_s
Second:
you can use string interpolation
"...Confirmation for #{#restaurant.name}"
I don't know whether this is intentional, but apparently #restaurant.name is returning a number (as you clarified, you're getting a TypeError: no implicit conversion of Fixnum into String). Calling #restaurant.name.to_s will solve that.
As G.B mentioned in another answer, string interpolation like "...Confirmation for #{#restaurant.name}" works too, since it calls #to_s for you automatically.
I'm putting the solution into an answer, since we found it while clarifying in the comments.
How I can parameterize to pass information between shared_example/include_examples?
In my specific case, I want to feed several constants to shared_example.
I found answer by myself... (I was hunting for answer for this two hours.. found this just after posting this)
At David Chelimsky's site, in article "Specifying mixins with shared example groups in RSpec-2," I found that shared_example can accept block parameters, and include_example can give parameters..
shared_example "example_1" do |param|
it "does something" do
xx.should == param
end
end
and later...
include_examples "example_1", :value_1
This work well with my case.
Note that, this parametalization is documented as cucumber feature, so I could find RSPec::Core document at Relish, but not in the class documentation.
I'm attempting to test a class which makes use of the rails configuration file. I'd like to mock Rails::configuration.
I've tried things like
Rails::singleton_class.expects(:configuration).returns('result')
Rails::singleton_class.stubs(:configuration).returns('result')
How do I go about doing this?
Rails.expects(:configuration).returns('result')
Please note there was a typo in your example. The returned value must be passed using returns, not return.
Also note, Rails.configuration returns Rails.application.config. If your method doesn't use Rails.configuration directly, it might actually bypass the call and your expectation won't work.
Rails.stubs(:configuration).returns(Rails::Application::Configuration.allocate)
This answer on mocking a Net response
helped