-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for the :if and :unless options
- Loading branch information
Showing
5 changed files
with
429 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper.rb' | ||
|
||
describe ActsAsApi::Base do | ||
|
||
describe "conditional statements", :orm => :active_record, :meow => true do | ||
|
||
before(:each) do | ||
setup_models | ||
end | ||
|
||
after(:each) do | ||
clean_up | ||
end | ||
|
||
describe "using the :if option" do | ||
|
||
describe "passing a symbol" do | ||
|
||
describe "that returns false" do | ||
|
||
before(:each) do | ||
@response = @luke.as_api_response(:if_over_thirty) | ||
end | ||
|
||
it "returns a hash" do | ||
@response.should be_kind_of(Hash) | ||
end | ||
|
||
it "returns the correct number of fields" do | ||
@response.should have(1).keys | ||
end | ||
|
||
it "won't add the conditional field but all others" do | ||
@response.keys.should include(:first_name) | ||
@response.keys.should_not include(:full_name) | ||
end | ||
|
||
it "the other specified fields have the correct value" do | ||
@response.values.should include(@luke.first_name) | ||
end | ||
|
||
end | ||
|
||
describe "that returns nil" do | ||
|
||
before(:each) do | ||
@response = @luke.as_api_response(:if_returns_nil) | ||
end | ||
|
||
it "returns a hash" do | ||
@response.should be_kind_of(Hash) | ||
end | ||
|
||
it "returns the correct number of fields" do | ||
@response.should have(1).keys | ||
end | ||
|
||
it "won't add the conditional field but all others" do | ||
@response.keys.should include(:first_name) | ||
@response.keys.should_not include(:full_name) | ||
end | ||
|
||
it "the other specified fields have the correct value" do | ||
@response.values.should include(@luke.first_name) | ||
end | ||
|
||
end | ||
|
||
describe "that returns true" do | ||
|
||
before(:each) do | ||
@response = @han.as_api_response(:if_over_thirty) | ||
end | ||
|
||
it "returns a hash" do | ||
@response.should be_kind_of(Hash) | ||
end | ||
|
||
it "returns the correct number of fields" do | ||
@response.should have(2).keys | ||
end | ||
|
||
it "won't add the conditional field but all others" do | ||
@response.keys.should include(:first_name) | ||
@response.keys.should include(:last_name) | ||
end | ||
|
||
it "the other specified fields have the correct value" do | ||
@response.values.should include(@han.first_name, @han.last_name) | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
|
||
describe "passing a proc" do | ||
|
||
describe "that returns false" do | ||
|
||
before(:each) do | ||
@response = @luke.as_api_response(:if_over_thirty_proc) | ||
end | ||
|
||
it "returns a hash" do | ||
@response.should be_kind_of(Hash) | ||
end | ||
|
||
it "returns the correct number of fields" do | ||
@response.should have(1).keys | ||
end | ||
|
||
it "won't add the conditional field but all others" do | ||
@response.keys.should include(:first_name) | ||
@response.keys.should_not include(:full_name) | ||
end | ||
|
||
it "the other specified fields have the correct value" do | ||
@response.values.should include(@luke.first_name) | ||
end | ||
|
||
end | ||
|
||
describe "that returns nil" do | ||
|
||
before(:each) do | ||
@response = @luke.as_api_response(:if_returns_nil_proc) | ||
end | ||
|
||
it "returns a hash" do | ||
@response.should be_kind_of(Hash) | ||
end | ||
|
||
it "returns the correct number of fields" do | ||
@response.should have(1).keys | ||
end | ||
|
||
it "won't add the conditional field but all others" do | ||
@response.keys.should include(:first_name) | ||
@response.keys.should_not include(:full_name) | ||
end | ||
|
||
it "the other specified fields have the correct value" do | ||
@response.values.should include(@luke.first_name) | ||
end | ||
|
||
end | ||
|
||
describe "that returns true" do | ||
|
||
before(:each) do | ||
@response = @han.as_api_response(:if_over_thirty_proc) | ||
end | ||
|
||
it "returns a hash" do | ||
@response.should be_kind_of(Hash) | ||
end | ||
|
||
it "returns the correct number of fields" do | ||
@response.should have(2).keys | ||
end | ||
|
||
it "won't add the conditional field but all others" do | ||
@response.keys.should include(:first_name) | ||
@response.keys.should include(:last_name) | ||
end | ||
|
||
it "the other specified fields have the correct value" do | ||
@response.values.should include(@han.first_name, @han.last_name) | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
end |
Oops, something went wrong.