Permalink
Browse files

refactoring shoulda macros

  • Loading branch information...
1 parent bafda28 commit 769d3b1ba9610d78b4b471cf7c36a3f52b5b854b @croaky croaky committed Dec 29, 2008
Showing with 78 additions and 5 deletions.
  1. +16 −5 shoulda_macros/sortable_table.rb
  2. +62 −0 test/rails_root/log/development.log
@@ -1,12 +1,10 @@
module SortableTable
module Shoulda
def should_sort_by(attribute, options = {}, &block)
- collection = self.name.underscore.gsub(/_controller_test/, '')
- collection.slice!(0..collection.rindex('/')) if collection.include?('/')
- collection = collection.to_sym
+ collection = get_collection_name_from_test_name
model_name = collection.to_s.singularize.camelize.constantize
- if !block
+ unless block
if model_name.columns.select{|c| c.name == attribute.to_s }.first.type == :boolean
block = lambda{|x| x.send(attribute).to_s }
end
@@ -65,7 +63,20 @@ def should_display_sortable_table_header_for(*valid_sorts)
}
end
end
- end
+ end
+
+ protected
+
+ def get_collection_name_from_test_name
+ collection = self.name.underscore.gsub(/_controller_test/, '')
+ collection = remove_namespacing(collection)
+ collection.to_sym
+ end
+
+ def remove_namespacing(string)
+ string.slice!(0..string.rindex('/')) if string.include?('/')
+ string
+ end
end
end
@@ -2873,3 +2873,65 @@ Migrating to UserBelongsToGroup (20081229222354)
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')
+ 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 (4.1ms) 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.7ms) 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.4ms) 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.3ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
+ SQL (1.5ms) 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 (2.5ms) INSERT INTO "schema_migrations" (version) VALUES ('20081229222354')
+ SQL (1.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20080819225020')
+ SQL (1.8ms) 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 (4.3ms) 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 (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.6ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
+ SQL (1.4ms) 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.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20081229222354')
+ SQL (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20080819225020')
+ SQL (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20081229222312')

0 comments on commit 769d3b1

Please sign in to comment.