Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Inspect should use getters for attributes values.

  • Loading branch information...
commit 8e89ee7d96ddb17ea4909163670b83181cdf16a5 1 parent 1890cd8
Joannic Laborde authored
2  lib/her/model/introspection.rb
View
@@ -12,7 +12,7 @@ module Introspection
# @user = User.find(1)
# p @user # => #<User(/users/1) id=1 name="Tobias Fünke">
def inspect
- "#<#{self.class}(#{request_path}) #{@data.inject([]) { |memo, item| key, value = item; memo << "#{key}=#{attribute_for_inspect(value)}"}.join(" ")}>"
+ "#<#{self.class}(#{request_path}) #{@data.keys.map { |k| "#{k}=#{attribute_for_inspect(send(k))}" }.join(" ")}>"
end
private
10 spec/model/introspection_spec.rb
View
@@ -19,15 +19,21 @@
end
describe "#inspect" do
- it "outputs resource attributs for an existing resource" do
+ it "outputs resource attributes for an existing resource" do
@user = Foo::User.find(1)
["#<Foo::User(users/1) name=\"Tobias Funke\" id=1>", "#<Foo::User(users/1) id=1 name=\"Tobias Funke\">"].should include(@user.inspect)
end
- it "outputs resource attributs for an not-saved-yet resource" do
+ it "outputs resource attributes for an not-saved-yet resource" do
@user = Foo::User.new(:name => "Tobias Funke")
@user.inspect.should == "#<Foo::User(users) name=\"Tobias Funke\">"
end
+
+ it "outputs resource attributes using getters" do
+ @user = Foo::User.new(:name => "Tobias Funke", :password => "Funke")
+ @user.instance_eval {def password; 'filtered'; end}
+ @user.inspect.should == "#<Foo::User(users) name=\"Tobias Funke\" password=\"filtered\">"
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.