Permalink
Browse files

Use new response macros

  • Loading branch information...
1 parent 8403bb8 commit ebbb1b1507c1e91885db51deabbf1d6348f744e1 @remiprev committed Mar 31, 2013
@@ -3,6 +3,9 @@
describe Her::Model::Associations do
context "for belongs_to association" do
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#belongs_to
+ #--------------------------------------------------------------------------------------------
describe :belongs_to do
before do
spawn_model 'Foo::User'
@@ -47,6 +50,9 @@
end
end
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#parse_associations
+ #--------------------------------------------------------------------------------------------
describe :parse_associations do
context "when association data is present" do
context "without additional association options" do
@@ -55,11 +61,11 @@
spawn_model('Foo::Organization')
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :organization => { :id => 1, :name => "Bluth Company" }, :organization_id => 1 }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :organization => { :id => 1, :name => "Bluth Company" }, :organization_id => 1 }
end
stub_api_for(Foo::Organization) do |stub|
- stub.get("/organizations/1") { |env| [200, {}, { :id => 2, :name => "Sitwell Enterprises" }.to_json] }
+ stub.get("/organizations/1") { ok! :id => 2, :name => "Sitwell Enterprises" }
end
end
@@ -80,7 +86,7 @@
spawn_model('Foo::Business')
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :biz => { :id => 1, :name => "Bluth Company" }, :organization_id => 1 }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :biz => { :id => 1, :name => "Bluth Company" }, :organization_id => 1 }
end
end
@@ -97,7 +103,7 @@
spawn_model('Foo::User') { belongs_to :organization }
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :organization => nil }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :organization => nil }
end
end
@@ -107,6 +113,9 @@
end
end
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#fetch_association
+ #--------------------------------------------------------------------------------------------
describe :fetch_association do
context "without additional association options" do
# TODO
@@ -3,6 +3,9 @@
describe Her::Model::Associations do
context "for has_many association" do
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#has_many
+ #--------------------------------------------------------------------------------------------
describe :has_many do
before do
spawn_model 'Foo::User'
@@ -47,6 +50,9 @@
end
end
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#parse_associations
+ #--------------------------------------------------------------------------------------------
describe :parse_associations do
context "when association data is present" do
context "without additional association options" do
@@ -55,11 +61,11 @@
spawn_model('Foo::Comment') { parse_root_in_json true }
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :comments => [{ :comment => { :id => 2, :body => "Tobias, you blow hard!", :user_id => 1 } }, { :comment => { :id => 3, :body => "I wouldn't mind kissing that man between the cheeks, so to speak", :user_id => 1 } }] }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :comments => [{ :comment => { :id => 2, :body => "Tobias, you blow hard!", :user_id => 1 } }, { :comment => { :id => 3, :body => "I wouldn't mind kissing that man between the cheeks, so to speak", :user_id => 1 } }] }
end
stub_api_for(Foo::Comment) do |stub|
- stub.get("/users/1/comments") { |env| [200, {}, [].to_json] }
+ stub.get("/users/1/comments") { ok! [] }
end
end
@@ -82,7 +88,7 @@
spawn_model('Foo::UserComment') { parse_root_in_json true }
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :user_comments => [{ :user_comment => { :id => 2, :body => "Tobias, you blow hard!", :user_id => 1 } }, { :user_comment => { :id => 3, :body => "I wouldn't mind kissing that man between the cheeks, so to speak", :user_id => 1 } }] }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :user_comments => [{ :user_comment => { :id => 2, :body => "Tobias, you blow hard!", :user_id => 1 } }, { :user_comment => { :id => 3, :body => "I wouldn't mind kissing that man between the cheeks, so to speak", :user_id => 1 } }] }
end
end
@@ -101,7 +107,7 @@
spawn_model('Foo::User') { has_many :comments }
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :comments => [] }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :comments => [] }
end
end
@@ -112,6 +118,9 @@
end
end
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#fetch_association
+ #--------------------------------------------------------------------------------------------
describe :fetch_association do
context "without additional association options" do
# TODO
@@ -3,6 +3,9 @@
describe Her::Model::Associations do
context "for has_one association" do
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#has_one
+ #--------------------------------------------------------------------------------------------
describe :has_one do
before do
spawn_model 'Foo::User'
@@ -47,6 +50,9 @@
end
end
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#parse_associations
+ #--------------------------------------------------------------------------------------------
describe :parse_associations do
context "when association data is present" do
context "without additional association options" do
@@ -55,11 +61,11 @@
spawn_model('Foo::Role')
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :role => { :id => 1, :name => "Admin" } }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :role => { :id => 1, :name => "Admin" } }
end
stub_api_for(Foo::Role) do |stub|
- stub.get("/users/1/role") { |env| [200, {}, { :id => 2, :name => "Super Admin" }.to_json] }
+ stub.get("/users/1/role") { ok! :id => 2, :name => "Super Admin" }
end
end
@@ -80,7 +86,7 @@
spawn_model('Foo::UserRole')
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :user_role => { :id => 1, :name => "Admin" } }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :user_role => { :id => 1, :name => "Admin" } }
end
end
@@ -96,7 +102,7 @@
spawn_model('Foo::User') { has_one :role }
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :role => nil }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :role => nil }
end
end
@@ -105,6 +111,9 @@
end
end
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#fetch_association
+ #--------------------------------------------------------------------------------------------
describe :fetch_association do
context "without additional association options" do
# TODO
@@ -4,18 +4,24 @@
describe Her::Model::Associations do
# See spec/model/associations/*.rb for additional specs
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#has_association?
+ #--------------------------------------------------------------------------------------------
describe :has_association? do
subject { spawn_model('Foo::User') { has_many :comments }.new }
it { should have_association(:comments) }
it { should_not have_association(:unknown_association) }
end
+ #--------------------------------------------------------------------------------------------
+ # Her::Model::Associations#get_association
+ #--------------------------------------------------------------------------------------------
describe :get_association do
before do
spawn_model('Foo::User') { has_many :comments }
stub_api_for(Foo::User) do |stub|
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke", :comments => [] }.to_json] }
+ stub.get("/users/1") { ok! :id => 1, :name => "Tobias Fünke", :comments => [] }
end
end
Oops, something went wrong.

0 comments on commit ebbb1b1

Please sign in to comment.