Last active
December 24, 2015 17:18
-
-
Save anlek/6833991 to your computer and use it in GitHub Desktop.
Mocha expects without casting
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
#Only include this during your tests, no need in Development or production. | |
class Hash | |
def stringify | |
inject({}){|memo,(k,v)| memo[k.to_s] = v.to_s; memo} | |
end | |
end |
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
FactoryGirl.define do | |
factory :price do | |
amount {rand(1..99).to_f} | |
name "MyString" | |
brief "MyString" | |
target {Price::VALID_TARGETS.sample.to_sym} | |
association :product, strategy: :build | |
end | |
end |
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
product.prices.any_instance.expects(:update).with(valid_attributes.stringify_keys) | |
put :update, {id: price.to_param, product_id: product.id, price: valid_attributes}, valid_session |
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
PricesController PUT update with valid params updates the requested price | |
Failure/Error: put :update, {id: price.to_param, product_id: product.id, price: valid_attributes}, valid_session | |
MiniTest::Assertion: | |
unexpected invocation: #<AnyInstance:Price>.update('amount' => '46.0', 'name' => 'MyString', 'brief' => 'MyString', 'target' => 'distributor') | |
unsatisfied expectations: | |
- expected exactly once, not yet invoked: #<AnyInstance:Price>.update('amount' => 46.0, 'name' => 'MyString', 'brief' => 'MyString', 'target' => :distributor) |
Also see the hash_ext.rb
file. I added it to my spec/support folder.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed issue by stringifying everything in the valid_attributes: