Permalink
Browse files

Update tests to reflect changes to object_node

  • Loading branch information...
1 parent ea0fac2 commit 098512fba1dad1d9b5244757ea29c0238245f5c8 @nesquena committed Apr 6, 2012
View
@@ -62,8 +62,9 @@
asserts "that it adds an attribute or method to be included in output" do
template = rabl %{
- object @user
- attribute :name
+ object @user do
+ attribute :name
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'irvine')
@@ -72,8 +73,9 @@
asserts "that it can add attribute under a different key name through :as" do
template = rabl %{
- object @user
- attribute :name, :as => 'city'
+ object @user do
+ attribute :name, :as => 'city'
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'irvine')
@@ -82,8 +84,9 @@
asserts "that it can add attribute under a different key name through hash" do
template = rabl %{
- object @user
- attribute :name => :city
+ object @user do
+ attribute :name => :city
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'irvine')
@@ -94,7 +97,7 @@
context "#code" do
- asserts "that it can create an arbitraty code node" do
+ asserts "that it can create an arbitrary code node" do
template = rabl %{
code(:foo) { 'bar' }
}
@@ -114,9 +117,10 @@
asserts "that it can create a child node" do
template = rabl %{
- object @user
- attribute :name
- child(@user) { attribute :city }
+ object @user do
+ attribute :name
+ child(@user) { attribute :city }
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
@@ -125,9 +129,10 @@
asserts "that it can create a child node with different key" do
template = rabl %{
- object @user
- attribute :name
- child(@user => :person) { attribute :city }
+ object @user do
+ attribute :name
+ child(@user => :person) { attribute :city }
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
@@ -139,10 +144,11 @@
asserts "that it glues data from a child node" do
template = rabl %{
- object @user
- attribute :name
- glue(@user) { attribute :city }
- glue(@user) { attribute :age }
+ object @user do
+ attribute :name
+ glue(@user) { attribute :city }
+ glue(@user) { attribute :age }
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12)
@@ -236,8 +242,9 @@ def self.serialize string
asserts "that it adds an attribute or method to be included in output" do
template = rabl %{
- object @user
- attribute :name
+ object @user do
+ attribute :name
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'irvine')
@@ -246,8 +253,9 @@ def self.serialize string
asserts "that it can add attribute under a different key name through :as" do
template = rabl %{
- object @user
- attribute :name, :as => 'city'
+ object @user do
+ attribute :name, :as => 'city'
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'irvine')
@@ -256,8 +264,9 @@ def self.serialize string
asserts "that it can add attribute under a different key name through hash" do
template = rabl %{
- object @user
- attribute :name => :city
+ object @user do
+ attribute :name => :city
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'irvine')
@@ -268,7 +277,7 @@ def self.serialize string
context "#code" do
- asserts "that it can create an arbitraty code node" do
+ asserts "that it can create an arbitrary code node" do
template = rabl %{
code(:foo) { 'bar' }
}
@@ -288,9 +297,10 @@ def self.serialize string
asserts "that it can create a child node" do
template = rabl %{
- object @user
- attribute :name
- child(@user) { attribute :city }
+ object @user do
+ attribute :name
+ child(@user) { attribute :city }
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
@@ -299,9 +309,10 @@ def self.serialize string
asserts "that it can create a child node with different key" do
template = rabl %{
- object @user
- attribute :name
- child(@user => :person) { attribute :city }
+ object @user do
+ attribute :name
+ child(@user => :person) { attribute :city }
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
@@ -313,10 +324,11 @@ def self.serialize string
asserts "that it glues data from a child node" do
template = rabl %{
- object @user
- attribute :name
- glue(@user) { attribute :city }
- glue(@user) { attribute :age }
+ object @user do
+ attribute :name
+ glue(@user) { attribute :city }
+ glue(@user) { attribute :age }
+ end
}
scope = Object.new
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12)
View
@@ -85,24 +85,21 @@
asserts "that it generates with an object" do
b = builder :child => [{ :data => @user, :options => {}, :block => lambda { |u| attribute :name } }]
- mock(b).data_name(@user) { :user }
- mock(b).object_to_hash(@user, { :root => false }).returns('xyz').subject
+ mock(b).data_name(@user) { :person }
b.build(@user)
- end.equivalent_to({ :user => 'xyz'})
+ end.equivalent_to({:person=>{:name=>"rabl"}})
asserts "that it generates with an collection and child_root" do
b = builder :child => [{ :data => @users, :options => {}, :block => lambda { |u| attribute :name } }], :child_root => true
mock(b).data_name(@users) { :users }
- mock(b).object_to_hash(@users, { :root => true, :child_root => true }).returns('xyz').subject
b.build(@user)
- end.equivalent_to({ :users => 'xyz'})
+ end.equivalent_to({:users => [{"user"=> {:name=>"rabl"}}, {"user"=>{:name=>"rabl"}}] })
asserts "that it generates with an collection and no child root" do
b = builder :child => [{ :data => @users, :options => {}, :block => lambda { |u| attribute :name } }], :child_root => false
mock(b).data_name(@users) { :users }
- mock(b).object_to_hash(@users, { :root => false, :child_root => false }).returns('xyz').subject
b.build(@user)
- end.equivalent_to({ :users => 'xyz'})
+ end.equivalent_to({:users => [{:name=>"rabl"}, {:name=>"rabl"}] })
end
context "#glue" do
@@ -112,18 +109,16 @@
asserts "that it generates the glue attributes" do
b = builder :glue => [{ :data => @user, :block => lambda { |u| attribute :name }}]
- mock(b).object_to_hash(@user, { :root => false }).returns({:user => 'xyz'}).subject
b.build(@user)
- end.equivalent_to({ :user => 'xyz' })
+ end.equivalent_to({:name=>"rabl"})
asserts "that it appends the glue attributes to result" do
b = builder :glue => [{ :data => @user, :block => lambda { |u| attribute :name => :user_name }}]
b.build(@user)
end.equivalent_to({ :user_name => 'rabl' })
asserts "that it does not generate new attributes if no glue attributes are present" do
- b = builder :glue => [{ :data => @user, :block => lambda { |u| attribute :name }}]
- mock(b).object_to_hash(@user,{ :root => false }).returns({}).subject
+ b = builder :glue => [{ :data => @user, :block => lambda { |u| }}]
b.build(@user)
end.equals({})
end
Oops, something went wrong.

0 comments on commit 098512f

Please sign in to comment.