Skip to content

Commit

Permalink
Making sure User#to_json and #to_yaml return the same stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Nov 11, 2009
1 parent 01cd9dc commit fc2f016
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -24,7 +24,7 @@ def to_json(options = {})
end

def to_yaml(*args)
{ :email => email }.to_yaml(*args)
{ 'email' => email }.to_yaml(*args)
end

protected
Expand Down
11 changes: 10 additions & 1 deletion test/unit/user_test.rb
Expand Up @@ -11,10 +11,19 @@ class UserTest < ActiveSupport::TestCase
@user = Factory(:user)
end

should "only have email when boiling down to json or yaml" do
json = JSON.parse(@user.to_json)
yaml = YAML.load(@user.to_yaml)

hash = {"email" => @user.email}
assert_equal hash, json
assert_equal hash, yaml
end

should "create api key" do
assert_not_nil @user.api_key
end

should "reset api key" do
assert_changed(@user, :api_key) do
@user.reset_api_key!
Expand Down

0 comments on commit fc2f016

Please sign in to comment.