acts_as_stripped 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.rvmrc +5 -0
- data/Gemfile +4 -0
- data/Rakefile +5 -55
- data/acts_as_stripped.gemspec +11 -40
- data/lib/acts_as_stripped.rb +5 -13
- data/lib/acts_as_stripped/version.rb +3 -0
- data/spec/acts_as_stripped_spec.rb +32 -0
- data/spec/database.yml +3 -0
- data/spec/spec_helper.rb +44 -0
- metadata +70 -23
- data/VERSION.yml +0 -5
- data/test/acts_as_stripped_test.rb +0 -39
- data/test/database.yml +0 -3
- data/test/test_helper.rb +0 -15
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,56 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "acts_as_stripped"
|
8
|
-
gem.summary = %Q{strip whitespace from string attributes}
|
9
|
-
gem.email = "ryan.sonnek@gmail.com"
|
10
|
-
gem.homepage = "http://github.com/wireframe/acts_as_stripped"
|
11
|
-
gem.authors = ["Ryan Sonnek"]
|
12
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
-
end
|
14
|
-
Jeweler::GemcutterTasks.new
|
15
|
-
rescue LoadError
|
16
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
-
end
|
18
|
-
|
19
|
-
require 'rake/testtask'
|
20
|
-
Rake::TestTask.new(:test) do |test|
|
21
|
-
test.libs << 'lib' << 'test'
|
22
|
-
test.pattern = 'test/**/*_test.rb'
|
23
|
-
test.verbose = true
|
24
|
-
end
|
25
|
-
|
26
|
-
begin
|
27
|
-
require 'rcov/rcovtask'
|
28
|
-
Rcov::RcovTask.new do |test|
|
29
|
-
test.libs << 'test'
|
30
|
-
test.pattern = 'test/**/*_test.rb'
|
31
|
-
test.verbose = true
|
32
|
-
end
|
33
|
-
rescue LoadError
|
34
|
-
task :rcov do
|
35
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
task :default => :test
|
41
|
-
|
42
|
-
require 'rake/rdoctask'
|
43
|
-
Rake::RDocTask.new do |rdoc|
|
44
|
-
if File.exist?('VERSION.yml')
|
45
|
-
config = YAML.load(File.read('VERSION.yml'))
|
46
|
-
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
-
else
|
48
|
-
version = ""
|
49
|
-
end
|
50
|
-
|
51
|
-
rdoc.rdoc_dir = 'rdoc'
|
52
|
-
rdoc.title = "acts_as_stripped #{version}"
|
53
|
-
rdoc.rdoc_files.include('README*')
|
54
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
56
3
|
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new('spec')
|
6
|
+
task :default => :spec
|
data/acts_as_stripped.gemspec
CHANGED
@@ -1,51 +1,22 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "acts_as_stripped/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
6
|
s.name = %q{acts_as_stripped}
|
8
|
-
s.version =
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
7
|
+
s.version = ActsAsStripped::VERSION
|
11
8
|
s.authors = ["Ryan Sonnek"]
|
12
|
-
s.date = %q{2010-06-15}
|
13
9
|
s.email = %q{ryan.sonnek@gmail.com}
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"LICENSE",
|
16
|
-
"README.rdoc"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".document",
|
20
|
-
".gitignore",
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION.yml",
|
25
|
-
"acts_as_stripped.gemspec",
|
26
|
-
"lib/acts_as_stripped.rb",
|
27
|
-
"test/acts_as_stripped_test.rb",
|
28
|
-
"test/database.yml",
|
29
|
-
"test/test_helper.rb"
|
30
|
-
]
|
31
10
|
s.homepage = %q{http://github.com/wireframe/acts_as_stripped}
|
32
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
-
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.7}
|
35
11
|
s.summary = %q{strip whitespace from string attributes}
|
36
|
-
s.
|
37
|
-
"test/acts_as_stripped_test.rb",
|
38
|
-
"test/test_helper.rb"
|
39
|
-
]
|
12
|
+
s.description = %q{ ActiveRecord Extension to strip whitespace from attributes before saving values }
|
40
13
|
|
41
|
-
|
42
|
-
|
43
|
-
|
14
|
+
s.add_runtime_dependency 'activerecord', ['>= 2.0']
|
15
|
+
s.add_development_dependency %q<rspec>, ['>= 2.5.0']
|
16
|
+
s.add_development_dependency(%q<sqlite3-ruby>, ["~> 1.3.2"])
|
44
17
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
50
22
|
end
|
51
|
-
|
data/lib/acts_as_stripped.rb
CHANGED
@@ -1,23 +1,17 @@
|
|
1
|
-
|
2
|
-
def self.included(base)
|
3
|
-
base.extend(ClassMethods)
|
4
|
-
end
|
1
|
+
require 'active_record'
|
5
2
|
|
3
|
+
module ActsAsStripped
|
6
4
|
module ClassMethods
|
7
5
|
def acts_as_stripped(*attrs)
|
8
|
-
|
9
|
-
self.acts_as_stripped_attributes = attrs
|
6
|
+
class_attribute :acts_as_stripped_attributes
|
7
|
+
self.acts_as_stripped_attributes = attrs
|
10
8
|
|
11
9
|
before_validation :strip_fields
|
12
10
|
|
13
11
|
include ActsAsStripped::InstanceMethods
|
14
|
-
extend ActsAsStripped::SingletonMethods
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
18
|
-
module SingletonMethods
|
19
|
-
end
|
20
|
-
|
21
15
|
module InstanceMethods
|
22
16
|
private
|
23
17
|
def strip_fields
|
@@ -28,6 +22,4 @@ module ActsAsStripped
|
|
28
22
|
end
|
29
23
|
end
|
30
24
|
|
31
|
-
|
32
|
-
ActiveRecord::Base.send(:include, ActsAsStripped)
|
33
|
-
end
|
25
|
+
ActiveRecord::Base.extend(ActsAsStripped::ClassMethods)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Post < ActiveRecord::Base
|
4
|
+
acts_as_stripped :title
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ActsAsStripped do
|
8
|
+
context 'a basic post instance' do
|
9
|
+
before do
|
10
|
+
@post = Post.new
|
11
|
+
end
|
12
|
+
it 'strips whitespace from title' do
|
13
|
+
@post.title = ' hello world '
|
14
|
+
@post.save!
|
15
|
+
|
16
|
+
@post.title.should == 'hello world'
|
17
|
+
end
|
18
|
+
it 'does not strip whitespace from body' do
|
19
|
+
@post.body = ' awesome '
|
20
|
+
@post.save!
|
21
|
+
|
22
|
+
@post.body.should == ' awesome '
|
23
|
+
end
|
24
|
+
it 'does not fail if title is nil' do
|
25
|
+
@post.title = nil
|
26
|
+
lambda do
|
27
|
+
@post.save!
|
28
|
+
end.should_not raise_error
|
29
|
+
@post.title.should be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/database.yml
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'acts_as_stripped'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
8
|
+
# in spec/support/ and its subdirectories.
|
9
|
+
# Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
10
|
+
|
11
|
+
# include Devise::TestHelpers
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
# == Mock Framework
|
15
|
+
#
|
16
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
17
|
+
#
|
18
|
+
# config.mock_with :mocha
|
19
|
+
# config.mock_with :flexmock
|
20
|
+
# config.mock_with :rr
|
21
|
+
config.mock_with :rspec
|
22
|
+
|
23
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
24
|
+
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
25
|
+
|
26
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
27
|
+
# examples within a transaction, remove the following line or assign false
|
28
|
+
# instead of true.
|
29
|
+
# config.use_transactional_fixtures = true
|
30
|
+
|
31
|
+
config.before(:suite) do
|
32
|
+
puts 'setting up database'
|
33
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
34
|
+
ActiveRecord::Base.logger = Logger.new STDOUT
|
35
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
|
36
|
+
|
37
|
+
ActiveRecord::Schema.define(:version => 1) do
|
38
|
+
create_table :posts, :force => true do |t|
|
39
|
+
t.column :title, :string
|
40
|
+
t.column :body, :string
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_stripped
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Sonnek
|
@@ -15,38 +15,84 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
date: 2011-08-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activerecord
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
version: "2.0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 27
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 5
|
47
|
+
- 0
|
48
|
+
version: 2.5.0
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: sqlite3-ruby
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 31
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 3
|
63
|
+
- 2
|
64
|
+
version: 1.3.2
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
description: " ActiveRecord Extension to strip whitespace from attributes before saving values "
|
23
68
|
email: ryan.sonnek@gmail.com
|
24
69
|
executables: []
|
25
70
|
|
26
71
|
extensions: []
|
27
72
|
|
28
|
-
extra_rdoc_files:
|
29
|
-
|
30
|
-
- README.rdoc
|
73
|
+
extra_rdoc_files: []
|
74
|
+
|
31
75
|
files:
|
32
76
|
- .document
|
33
77
|
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .rvmrc
|
80
|
+
- Gemfile
|
34
81
|
- LICENSE
|
35
82
|
- README.rdoc
|
36
83
|
- Rakefile
|
37
|
-
- VERSION.yml
|
38
84
|
- acts_as_stripped.gemspec
|
39
85
|
- lib/acts_as_stripped.rb
|
40
|
-
-
|
41
|
-
-
|
42
|
-
-
|
43
|
-
|
86
|
+
- lib/acts_as_stripped/version.rb
|
87
|
+
- spec/acts_as_stripped_spec.rb
|
88
|
+
- spec/database.yml
|
89
|
+
- spec/spec_helper.rb
|
44
90
|
homepage: http://github.com/wireframe/acts_as_stripped
|
45
91
|
licenses: []
|
46
92
|
|
47
93
|
post_install_message:
|
48
|
-
rdoc_options:
|
49
|
-
|
94
|
+
rdoc_options: []
|
95
|
+
|
50
96
|
require_paths:
|
51
97
|
- lib
|
52
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -70,10 +116,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
116
|
requirements: []
|
71
117
|
|
72
118
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.
|
119
|
+
rubygems_version: 1.8.5
|
74
120
|
signing_key:
|
75
121
|
specification_version: 3
|
76
122
|
summary: strip whitespace from string attributes
|
77
123
|
test_files:
|
78
|
-
-
|
79
|
-
-
|
124
|
+
- spec/acts_as_stripped_spec.rb
|
125
|
+
- spec/database.yml
|
126
|
+
- spec/spec_helper.rb
|
data/VERSION.yml
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
ActiveRecord::Schema.define(:version => 1) do
|
4
|
-
create_table :posts, :force => true do |t|
|
5
|
-
t.column :title, :string
|
6
|
-
t.column :body, :string
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class Post < ActiveRecord::Base
|
11
|
-
acts_as_stripped :title
|
12
|
-
end
|
13
|
-
|
14
|
-
class ActsAsStrippedTest < Test::Unit::TestCase
|
15
|
-
context 'a basic post instance' do
|
16
|
-
setup do
|
17
|
-
@post = Post.new
|
18
|
-
end
|
19
|
-
should 'strip whitespace from title' do
|
20
|
-
@post.title = ' hello world '
|
21
|
-
@post.save!
|
22
|
-
|
23
|
-
assert_equal 'hello world', @post.title
|
24
|
-
end
|
25
|
-
should 'not strip whitespace from body' do
|
26
|
-
@post.body = ' awesome '
|
27
|
-
@post.save!
|
28
|
-
|
29
|
-
assert_equal ' awesome ', @post.body
|
30
|
-
end
|
31
|
-
should 'not fail if title is nil' do
|
32
|
-
@post.title = nil
|
33
|
-
assert_nothing_raised do
|
34
|
-
@post.save!
|
35
|
-
end
|
36
|
-
assert_nil @post.title
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/test/database.yml
DELETED
data/test/test_helper.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'shoulda'
|
4
|
-
require 'activerecord'
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
-
require 'acts_as_stripped'
|
9
|
-
|
10
|
-
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
11
|
-
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
12
|
-
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
|
13
|
-
|
14
|
-
class Test::Unit::TestCase
|
15
|
-
end
|