/friendship_excerpt.rb Secret
Created
February 25, 2013 04:12
-
-
Save joho/5d3225cd6c0608d39921 to your computer and use it in GitHub Desktop.
This file contains 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
# Just to show you what is actually in our code base, as opposed to the slightly artificial test above. | |
class Friendship < ActiveRecord::Base | |
def self.ensure_following(follower, followee, social_network = nil, send_new_follower_notification = true) | |
created_a_friendship = false | |
friendship = where(user_id: follower.id, friend_id: followee.id).first_or_create do |record| | |
record.from_social_network = social_network | |
created_a_friendship = true | |
end | |
if created_a_friendship && send_new_follower_notification | |
# HACK: for some reason whatever is returned from the | |
# chained scope.first_or_create will crash when to_yaml | |
# is called (part of assigning payload_object on the delayed job) | |
# I *think* this is because there is some kind of relationship | |
# proxy there messing it up. | |
# NOTE (the reload is the workaround, old code was just friendship.delay) | |
friendship.reload.delay.send_new_follower_notification | |
end | |
friendship | |
end | |
end |
This file contains 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
joho5[15:04:04]:~/source/goodfilms/site(master)!! | |
♺ bin/rspec --backtrace spec/models/yaml_bullshit_spec.rb | |
Rack::File headers parameter replaces cache_control after Rack 1.5. | |
F | |
Failures: | |
1) some yaml bullshit with delayed job should not fuck out on a friendship | |
Failure/Error: friendship.to_yaml | |
ArgumentError: | |
wrong number of arguments (2 for 1) | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:220:in `binary?' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:229:in `visit_String' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:282:in `block in visit_Hash' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:280:in `each' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:280:in `visit_Hash' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:387:in `block in emit_coder' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:385:in `each' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:385:in `emit_coder' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:370:in `dump_coder' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:100:in `accept' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:66:in `push' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych.rb:189:in `dump' | |
# /Users/joho/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/psych/core_ext.rb:14:in `psych_to_yaml' | |
# ./spec/models/yaml_bullshit_spec.rb:13:in `block (2 levels) in <top (required)>' | |
Finished in 0.18934 seconds | |
1 example, 1 failure | |
Failed examples: | |
rspec ./spec/models/yaml_bullshit_spec.rb:5 # some yaml bullshit with delayed job should not fuck out on a friendship |
This file contains 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
require 'spec_helper' | |
describe "some yaml bullshit with delayed job" do | |
it "should not fuck out on a friendship" do | |
user_one = Factory(:user) | |
user_two = Factory(:user) | |
friendship = Friendship.where(user_id: user_one.id, friend_id: user_two.id).first_or_create do |record| | |
record.from_social_network = :facebook | |
end | |
friendship.to_yaml | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment