Created
September 3, 2010 14:59
-
-
Save knewter/563987 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
==== Here's a spec ===== | |
require 'spec_helper' | |
describe Project do | |
it "fails validation with no name" do | |
Project.new.should have(1).errors_on(:name) | |
end | |
context "with an existing project with the same name on a given client" do | |
before(:each) do | |
@client = Client.create(:name => 'testee', :status => 'testee') | |
@project = Project.create(:name => 'test', :client => @client) | |
end | |
it "requires unique names scoped by client" do | |
p = Project.new(:name => 'test', :client => @client) | |
p.valid? | |
p.should have(1).errors_on(:name) | |
end | |
end | |
end | |
=== Here's the output in test.log from running it === | |
Notice there's no transaction rollback. | |
--(jadams@acer-is-win)-(7/pts/3)-(0957/03-Sep-10)-- | |
--($:~/rails/asset_tracker_tutorial_pre)(work)-- tail -n1000 -f log/test.log | |
SQL (0.4ms) SHOW TABLES | |
Project Load (0.3ms) SELECT `projects`.`id` FROM `projects` WHERE (`projects`.`name` IS NULL) AND (`projects`.`client_id` IS NULL) LIMIT 1 | |
SQL (0.1ms) BEGIN | |
Client Load (0.3ms) SELECT `clients`.`id` FROM `clients` WHERE (`clients`.`name` = BINARY 'testee') LIMIT 1 | |
SQL (12.1ms) describe `clients` | |
SQL (0.3ms) INSERT INTO `clients` (`created_at`, `name`, `status`, `updated_at`) VALUES ('2010-09-03 14:59:19', 'testee', 'testee', '2010-09-03 14:59:19') | |
SQL (137.6ms) COMMIT | |
SQL (0.1ms) BEGIN | |
Project Load (0.4ms) SELECT `projects`.`id` FROM `projects` WHERE (`projects`.`name` = BINARY 'test') AND (`projects`.`client_id` = 2) LIMIT 1 | |
SQL (0.7ms) describe `projects` | |
SQL (0.2ms) INSERT INTO `projects` (`client_id`, `created_at`, `name`, `updated_at`) VALUES (2, '2010-09-03 14:59:19', 'test', '2010-09-03 14:59:19') | |
SQL (64.5ms) COMMIT | |
Project Load (1.1ms) SELECT `projects`.`id` FROM `projects` WHERE (`projects`.`name` = BINARY 'test') AND (`projects`.`client_id` = 2) LIMIT 1 | |
Project Load (5.2ms) SELECT `projects`.`id` FROM `projects` WHERE (`projects`.`name` = BINARY 'test') AND (`projects`.`client_id` = 2) LIMIT 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment