This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

creating Group model in test suite to set up testing edge cases of so…

…rtable table usage
  • Loading branch information...
croaky committed Dec 29, 2008
1 parent a29b40f commit bafda285b95341c8aabd3e539662ce53f57a6b29
@@ -0,0 +1,2 @@
+class Group < ActiveRecord::Base
+end
@@ -1,2 +1,3 @@
class User < ActiveRecord::Base
+ belongs_to :group
end
@@ -22,5 +22,18 @@
:session_key => '_rails_root_session',
:secret => '6042b566bbfa8e55bdb33a4b3b39b3c373e035c0a87b587a614db4c8bfea19a7adbd49f2098d4c995e37b28f6539e309f4bc5885cf023b47d5fe9d4450be2d46'
}
+
+ config.gem 'mocha',
+ :version => '>= 0.9.3'
+ config.gem 'quietbacktrace',
+ :version => '>= 0.1.1'
+ config.gem 'thoughtbot-factory_girl',
+ :lib => 'factory_girl',
+ :source => 'http://gems.github.com',
+ :version => '>= 1.1.5'
+ config.gem 'thoughtbot-shoulda',
+ :lib => 'shoulda',
+ :source => 'http://gems.github.com',
+ :version => '>= 2.0.6'
end
Binary file not shown.
@@ -0,0 +1,13 @@
+class CreateGroups < ActiveRecord::Migration
+ def self.up
+ create_table :groups do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :groups
+ end
+end
@@ -0,0 +1,10 @@
+class UserBelongsToGroup < ActiveRecord::Migration
+ def self.up
+ add_column :users, :group_id, :integer
+ add_index :users, :group_id
+ end
+
+ def self.down
+ remove_column :users, :group_id
+ end
+end
@@ -9,7 +9,13 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20080819225020) do
+ActiveRecord::Schema.define(:version => 20081229222354) do
+
+ create_table "groups", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
create_table "users", :force => true do |t|
t.string "name"
@@ -18,6 +24,9 @@
t.integer "age"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "group_id"
end
+ add_index "users", ["group_id"], :name => "index_users_on_group_id"
+
end
Binary file not shown.
@@ -2717,3 +2717,159 @@ Processing UsersController#index (for 127.0.0.1 at 2008-10-30 11:14:18) [GET]
Rendering template within layouts/users
Rendering users/index
Completed in 0.14385 (6 reqs/sec) | Rendering: 0.13151 (91%) | DB: 0.00290 (2%) | 200 OK [http://localhost/users]
+ SQL (1.1ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.5ms) SELECT version FROM schema_migrations
+ SQL (0.5ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.4ms) SELECT version FROM schema_migrations
+Migrating to CreateUsers (20080819225020)
+ SQL (2.3ms) DROP TABLE "users"
+ SQL (1.6ms) DELETE FROM schema_migrations WHERE version = '20080819225020'
+ SQL (28.0ms) select sqlite_version(*)
+ SQL (0.4ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.2ms) SELECT version FROM schema_migrations
+ SQL (0.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.5ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.1ms) SELECT version FROM schema_migrations
+Migrating to CreateUsers (20080819225020)
+ SQL (0.2ms) select sqlite_version(*)
+ SQL (1.6ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "admin" boolean, "age" integer, "created_at" datetime, "updated_at" datetime) 
+ SQL (1.9ms) INSERT INTO schema_migrations (version) VALUES ('20080819225020')
+Migrating to CreateGroups (20081229222312)
+ SQL (1.3ms) CREATE TABLE "groups" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime) 
+ SQL (1.5ms) INSERT INTO schema_migrations (version) VALUES ('20081229222312')
+Migrating to UserBelongsToGroup (20081229222354)
+ SQL (1.4ms) ALTER TABLE "users" ADD "integer" group_id
+ SQL (38.7ms) VACUUM
+ SQL (0.0ms) SQLite3::SQLException: table users has no column named group_id: CREATE INDEX "index_users_on_group_id" ON "users" ("group_id")
+ SQL (0.6ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.2ms) SELECT version FROM schema_migrations
+ SQL (0.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.2ms) SELECT version FROM schema_migrations
+Migrating to CreateGroups (20081229222312)
+ SQL (2.1ms) DROP TABLE "groups"
+ SQL (1.5ms) DELETE FROM schema_migrations WHERE version = '20081229222312'
+Migrating to CreateUsers (20080819225020)
+ SQL (1.5ms) DROP TABLE "users"
+ SQL (2.0ms) DELETE FROM schema_migrations WHERE version = '20080819225020'
+ SQL (0.3ms) select sqlite_version(*)
+ SQL (0.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.1ms) SELECT version FROM schema_migrations
+ SQL (0.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.5ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.1ms) SELECT version FROM schema_migrations
+Migrating to CreateUsers (20080819225020)
+ SQL (0.2ms) select sqlite_version(*)
+ SQL (1.9ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "admin" boolean, "age" integer, "created_at" datetime, "updated_at" datetime) 
+ SQL (1.3ms) INSERT INTO schema_migrations (version) VALUES ('20080819225020')
+Migrating to CreateGroups (20081229222312)
+ SQL (1.3ms) CREATE TABLE "groups" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime) 
+ SQL (1.5ms) INSERT INTO schema_migrations (version) VALUES ('20081229222312')
+Migrating to UserBelongsToGroup (20081229222354)
+ SQL (1.3ms) ALTER TABLE "users" ADD "group_id" integer
+ SQL (3.4ms) VACUUM
+ SQL (1.7ms) CREATE INDEX "index_users_on_group_id" ON "users" ("group_id")
+ SQL (1.3ms) INSERT INTO schema_migrations (version) VALUES ('20081229222354')
+ SQL (0.4ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.3ms) SELECT version FROM schema_migrations
+ SQL (0.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.1ms) PRAGMA index_list("groups")
+ SQL (0.2ms) PRAGMA index_list("users")
+ SQL (0.1ms) PRAGMA index_info('index_users_on_group_id')
+ SQL (0.8ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.3ms) SELECT version FROM schema_migrations
+ SQL (0.3ms) select sqlite_version(*)
+ SQL (0.2ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.7ms) CREATE TABLE "groups" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime) 
+ SQL (0.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.1ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "admin" boolean, "age" integer, "created_at" datetime, "updated_at" datetime, "group_id" integer) 
+ SQL (3.0ms) CREATE INDEX "index_users_on_group_id" ON "users" ("group_id")
+ SQL (0.4ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
+ SQL (1.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
+ SQL (0.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
+ SQL (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20081229222354')
+ SQL (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20080819225020')
+ SQL (1.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20081229222312')
+ SQL (0.7ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.3ms) SELECT version FROM schema_migrations
+ SQL (0.2ms) select sqlite_version(*)
+ SQL (0.2ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.6ms) CREATE TABLE "groups" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime) 
+ SQL (0.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "admin" boolean, "age" integer, "created_at" datetime, "updated_at" datetime, "group_id" integer) 
+ SQL (1.1ms) CREATE INDEX "index_users_on_group_id" ON "users" ("group_id")
+ SQL (0.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
+ SQL (2.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
+ SQL (0.4ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
+ SQL (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20081229222354')
+ SQL (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20080819225020')
+ SQL (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20081229222312')
@@ -1,7 +1,12 @@
Factory.define :user do |user|
user.email { Factory.next :email }
- user.name { Factory.next :name }
- user.age { Factory.next :age }
+ user.name { Factory.next :name }
+ user.age { Factory.next :age }
+ user.group { |user| user.association(:group) }
+end
+
+Factory.define :group do |group|
+ group.name { Factory.next :name }
end
Factory.sequence :email do |each|
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class GroupTest < ActiveSupport::TestCase
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class UserTest < ActiveSupport::TestCase
+ context "a User" do
+ setup { Factory :user }
+ should_belong_to :group
+ end
+end

0 comments on commit bafda28

Please sign in to comment.