Created
September 10, 2010 21:18
-
-
Save ess/574392 to your computer and use it in GitHub Desktop.
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
require 'spec_helper' | |
describe Account do | |
before(:each) do | |
@account = Account.new( | |
:first_name => 'obligatory', | |
:last_name => 'name', | |
:email => 'email@address', | |
:address => '123 Any St.', | |
:city => 'Omaha', | |
:state => 'NE', | |
:postal => '55555', | |
:country => 'US' | |
) | |
end | |
it { should validate_presence_of( :first_name ) } | |
it { should validate_presence_of( :last_name ) } | |
it { should validate_presence_of( :email ) } | |
it { should validate_presence_of( :address ) } | |
it { should validate_presence_of( :city ) } | |
it { should validate_presence_of( :state ) } | |
it { should validate_presence_of( :postal ) } | |
it { should validate_presence_of( :country ) } | |
it "is valid with only known attributes" do | |
@account.unknown_attributes_not_allowed | |
@account.should be_valid | |
end | |
is "is not valid with unknown attributes" do | |
@account['towel'] = 'forgotten' | |
@account.unknown_attributes_not_allowed | |
@acciount.should_not be_valid | |
end | |
end |
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
Feature: JSON API Account list | |
In order to integrate a client with Operator | |
As a developer | |
I want to get a list of all accounts | |
Background: | |
Given I send and accept JSON | |
Scenario: List all accounts (when there are no accounts) | |
Given there are no accounts | |
When I GET "/account" | |
Then the response status should be "200" | |
And I should see the JSON: | |
""" | |
[] | |
""" | |
Scenario: List all accounts (when there are existing accounts) | |
Given there are accounts | |
When I GET "/account" | |
Then the response status should be "200" | |
And I should see the JSON: | |
""" | |
[] | |
""" |
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
def fixtimes(something) | |
if something.is_a? Hash | |
something["created_at"] = ActiveSupport::JSON.decode(Time.parse(something["created_at"]).localtime.to_json) if something.has_key? "created_at" | |
something["updated_at"] = ActiveSupport::JSON.decode(Time.parse(something["updated_at"]).localtime.to_json) if something.has_key? "updated_at" | |
something.each_key do |key| | |
something[key] = fixtimes(something[key]) | |
end | |
end | |
if something.is_a? Array | |
something.collect! { |x| fixtimes(x) } | |
end | |
something | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given /^there are accounts$/ do
Factory.build(:steven)
Factory.build(:bill)
end