Created
July 15, 2011 16:33
-
-
Save dchelimsky/1085028 to your computer and use it in GitHub Desktop.
assign temporary value to an attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with_attribute(SomeModel, :record_timestamps).temporarily(false) do | |
model_instance.update_attributes(:updated_at => 35.minutes.ago) | |
end | |
with_attribute(SomeModel, :record_timestamps, false) do | |
model_instance.update_attributes(:updated_at => 35.minutes.ago) | |
end | |
SomeModel.with(:record_timestamps, false) do # with, with_temp, with_attr??? | |
model_instance.update_attributes(:updated_at => 35.minutes.ago) | |
end | |
# would be great if we could do something like this, but how?????? | |
SomeModel.record_timestamps.temporarily(false) do | |
model_instance.update_attributes(:updated_at => 35.minutes.ago) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So what we're doing here is really just stubbing out a method, but only within the block. If RSpec's
Object#stub
method didn't already take a block (to define the value of the stubbed method dynamically/lazily), then we could do this:So maybe we should use a variant of
stub
:NOTE: I just looked at the RSpec code, and it seems to support the hash syntax I'm using here, but it's not documented.