Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan Sonnek
committed
Jun 24, 2009
1 parent
5fa5e83
commit 73e92fd
Showing
6 changed files
with
137 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
coverage | ||
rdoc | ||
pkg | ||
*.sqlite3 |
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,28 @@ | ||
module ActsAsStripped | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def acts_as_stripped | ||
before_validation :strip_fields | ||
|
||
include ActsAsStripped::InstanceMethods | ||
extend ActsAsStripped::SingletonMethods | ||
end | ||
end | ||
|
||
module SingletonMethods | ||
end | ||
|
||
module InstanceMethods | ||
private | ||
def strip_fields | ||
self.attributes.each_key {|a| self[a].strip! if self[a].respond_to? :strip! } | ||
end | ||
end | ||
end | ||
|
||
if Object.const_defined?("ActiveRecord") | ||
ActiveRecord::Base.send(:include, ActsAsStripped) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
require 'test_helper' | ||
|
||
ActiveRecord::Schema.define(:version => 1) do | ||
create_table :users, :force => true do |t| | ||
t.column :first_name, :string | ||
t.column :last_name, :string | ||
end | ||
end | ||
|
||
class User < ActiveRecord::Base | ||
acts_as_stripped | ||
end | ||
|
||
class ActsAsStrippedTest < Test::Unit::TestCase | ||
should "probably rename this file and start testing for real" do | ||
flunk "hey buddy, you should probably rename this file and start testing for real" | ||
context 'a basic user instance' do | ||
setup do | ||
@user = User.new | ||
end | ||
should "strips all attributes of extra whitespace" do | ||
@user.first_name = ' ryan ' | ||
@user.last_name = ' sonnek ' | ||
|
||
@user.save! | ||
assert_equal 'ryan', @user.first_name | ||
assert_equal 'sonnek', @user.last_name | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sqlite: | ||
:adapter: sqlite3 | ||
:dbfile: acts_as_stripped.sqlite3 |
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,77 @@ | ||
# Logfile created on Wed Jun 24 17:11:52 -0500 2009 by / | ||
[4;36;1mSQL (0.6ms)[0m [0;1mselect sqlite_version(*)[0m | ||
[4;35;1mSQL (0.4ms)[0m [0m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;36;1mSQL (2.5ms)[0m [0;1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_name" varchar(255), "last_name" varchar(255)) [0m | ||
[4;35;1mSQL (0.6ms)[0m [0m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;36;1mSQL (2.0ms)[0m [0;1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m | ||
[4;35;1mSQL (2.5ms)[0m [0mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m | ||
[4;36;1mSQL (0.7ms)[0m [0;1m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;35;1mSQL (0.5ms)[0m [0mSELECT version FROM "schema_migrations"[0m | ||
[4;36;1mSQL (2.4ms)[0m [0;1mINSERT INTO "schema_migrations" (version) VALUES ('1')[0m | ||
[4;35;1mSQL (0.7ms)[0m [0m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;36;1mSQL (0.6ms)[0m [0;1mselect sqlite_version(*)[0m | ||
[4;35;1mSQL (0.8ms)[0m [0m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;36;1mSQL (3.3ms)[0m [0;1mDROP TABLE "users"[0m | ||
[4;35;1mSQL (2.1ms)[0m [0mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_name" varchar(255), "last_name" varchar(255)) [0m | ||
[4;36;1mSQL (0.8ms)[0m [0;1m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;35;1mSQL (1.8ms)[0m [0mSELECT version FROM "schema_migrations"[0m | ||
[4;36;1mUser Create (0.6ms)[0m [0;1mINSERT INTO "users" ("last_name", "first_name") VALUES(' sonnek ', ' ryan ')[0m | ||
[4;36;1mSQL (0.7ms)[0m [0;1mselect sqlite_version(*)[0m | ||
[4;35;1mSQL (0.9ms)[0m [0m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;36;1mSQL (3.7ms)[0m [0;1mDROP TABLE "users"[0m | ||
[4;35;1mSQL (2.1ms)[0m [0mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_name" varchar(255), "last_name" varchar(255)) [0m | ||
[4;36;1mSQL (0.6ms)[0m [0;1m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;35;1mSQL (0.3ms)[0m [0mSELECT version FROM "schema_migrations"[0m | ||
[4;36;1mSQL (0.6ms)[0m [0;1m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;36;1mSQL (0.6ms)[0m [0;1mselect sqlite_version(*)[0m | ||
[4;35;1mSQL (0.7ms)[0m [0m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;36;1mSQL (3.1ms)[0m [0;1mDROP TABLE "users"[0m | ||
[4;35;1mSQL (2.2ms)[0m [0mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_name" varchar(255), "last_name" varchar(255)) [0m | ||
[4;36;1mSQL (0.8ms)[0m [0;1m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;35;1mSQL (0.5ms)[0m [0mSELECT version FROM "schema_migrations"[0m | ||
[4;36;1mSQL (0.6ms)[0m [0;1mselect sqlite_version(*)[0m | ||
[4;35;1mSQL (0.8ms)[0m [0m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;36;1mSQL (3.1ms)[0m [0;1mDROP TABLE "users"[0m | ||
[4;35;1mSQL (2.2ms)[0m [0mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_name" varchar(255), "last_name" varchar(255)) [0m | ||
[4;36;1mSQL (0.5ms)[0m [0;1m SELECT name | ||
FROM sqlite_master | ||
WHERE type = 'table' AND NOT name = 'sqlite_sequence' | ||
[0m | ||
[4;35;1mSQL (0.4ms)[0m [0mSELECT version FROM "schema_migrations"[0m | ||
[4;36;1mUser Create (0.6ms)[0m [0;1mINSERT INTO "users" ("last_name", "first_name") VALUES('sonnek', 'ryan')[0m |
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
require 'rubygems' | ||
require 'test/unit' | ||
require 'shoulda' | ||
require 'activerecord' | ||
|
||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
require 'acts_as_stripped' | ||
|
||
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) | ||
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") | ||
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite']) | ||
|
||
class Test::Unit::TestCase | ||
end |