acts_as_defaultable 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +35 -39
- data/README.rdoc +3 -1
- data/acts_as_defaultable.gemspec +4 -2
- data/lib/acts_as_defaultable.rb +3 -1
- data/lib/acts_as_defaultable/version.rb +1 -1
- data/spec/dummy/app/models/test_default.rb +3 -0
- data/spec/dummy/db/migrate/20120104234100_create_test_defaults.rb +9 -0
- data/spec/dummy/db/schema.rb +34 -1
- data/spec/factories/test_default.rb +11 -0
- data/spec/models/test_default_spec.rb +56 -0
- metadata +46 -20
data/Gemfile
CHANGED
@@ -6,7 +6,7 @@ source "http://rubygems.org"
|
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
# jquery-rails is used by the dummy application
|
9
|
-
gem "jquery-rails"
|
9
|
+
#gem "jquery-rails"
|
10
10
|
|
11
11
|
# Declare any dependencies that are still in development here instead of in
|
12
12
|
# your gemspec. These might include edge Rails or gems from your path or
|
data/Gemfile.lock
CHANGED
@@ -17,40 +17,40 @@ GIT
|
|
17
17
|
PATH
|
18
18
|
remote: .
|
19
19
|
specs:
|
20
|
-
acts_as_defaultable (0.0.
|
21
|
-
rails (
|
20
|
+
acts_as_defaultable (0.0.3)
|
21
|
+
rails (= 3.2.0)
|
22
22
|
|
23
23
|
GEM
|
24
24
|
remote: http://rubygems.org/
|
25
25
|
specs:
|
26
|
-
actionmailer (3.2.0
|
27
|
-
actionpack (= 3.2.0
|
28
|
-
mail (~> 2.
|
29
|
-
actionpack (3.2.0
|
30
|
-
activemodel (= 3.2.0
|
31
|
-
activesupport (= 3.2.0
|
26
|
+
actionmailer (3.2.0)
|
27
|
+
actionpack (= 3.2.0)
|
28
|
+
mail (~> 2.4.0)
|
29
|
+
actionpack (3.2.0)
|
30
|
+
activemodel (= 3.2.0)
|
31
|
+
activesupport (= 3.2.0)
|
32
32
|
builder (~> 3.0.0)
|
33
33
|
erubis (~> 2.7.0)
|
34
|
-
journey (~> 1.0.0
|
34
|
+
journey (~> 1.0.0)
|
35
35
|
rack (~> 1.4.0)
|
36
36
|
rack-cache (~> 1.1)
|
37
37
|
rack-test (~> 0.6.1)
|
38
38
|
sprockets (~> 2.1.2)
|
39
|
-
activemodel (3.2.0
|
40
|
-
activesupport (= 3.2.0
|
39
|
+
activemodel (3.2.0)
|
40
|
+
activesupport (= 3.2.0)
|
41
41
|
builder (~> 3.0.0)
|
42
|
-
activerecord (3.2.0
|
43
|
-
activemodel (= 3.2.0
|
44
|
-
activesupport (= 3.2.0
|
45
|
-
arel (~> 3.0.0
|
42
|
+
activerecord (3.2.0)
|
43
|
+
activemodel (= 3.2.0)
|
44
|
+
activesupport (= 3.2.0)
|
45
|
+
arel (~> 3.0.0)
|
46
46
|
tzinfo (~> 0.3.29)
|
47
|
-
activeresource (3.2.0
|
48
|
-
activemodel (= 3.2.0
|
49
|
-
activesupport (= 3.2.0
|
50
|
-
activesupport (3.2.0
|
47
|
+
activeresource (3.2.0)
|
48
|
+
activemodel (= 3.2.0)
|
49
|
+
activesupport (= 3.2.0)
|
50
|
+
activesupport (3.2.0)
|
51
51
|
i18n (~> 0.6)
|
52
52
|
multi_json (~> 1.0)
|
53
|
-
arel (3.0.0
|
53
|
+
arel (3.0.0)
|
54
54
|
builder (3.0.0)
|
55
55
|
diff-lcs (1.1.3)
|
56
56
|
erubis (2.7.0)
|
@@ -67,13 +67,10 @@ GEM
|
|
67
67
|
guard (>= 0.10.0)
|
68
68
|
hike (1.2.1)
|
69
69
|
i18n (0.6.0)
|
70
|
-
journey (1.0.0
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
json (1.6.4)
|
75
|
-
libnotify (0.7.1)
|
76
|
-
mail (2.3.0)
|
70
|
+
journey (1.0.0)
|
71
|
+
json (1.6.5)
|
72
|
+
libnotify (0.7.0)
|
73
|
+
mail (2.4.1)
|
77
74
|
i18n (>= 0.4.0)
|
78
75
|
mime-types (~> 1.16)
|
79
76
|
treetop (~> 1.4.8)
|
@@ -81,24 +78,24 @@ GEM
|
|
81
78
|
multi_json (1.0.4)
|
82
79
|
mysql2 (0.3.11)
|
83
80
|
polyglot (0.3.3)
|
84
|
-
rack (1.4.
|
81
|
+
rack (1.4.1)
|
85
82
|
rack-cache (1.1)
|
86
83
|
rack (>= 0.4)
|
87
84
|
rack-ssl (1.3.2)
|
88
85
|
rack
|
89
86
|
rack-test (0.6.1)
|
90
87
|
rack (>= 1.0)
|
91
|
-
rails (3.2.0
|
92
|
-
actionmailer (= 3.2.0
|
93
|
-
actionpack (= 3.2.0
|
94
|
-
activerecord (= 3.2.0
|
95
|
-
activeresource (= 3.2.0
|
96
|
-
activesupport (= 3.2.0
|
88
|
+
rails (3.2.0)
|
89
|
+
actionmailer (= 3.2.0)
|
90
|
+
actionpack (= 3.2.0)
|
91
|
+
activerecord (= 3.2.0)
|
92
|
+
activeresource (= 3.2.0)
|
93
|
+
activesupport (= 3.2.0)
|
97
94
|
bundler (~> 1.0)
|
98
|
-
railties (= 3.2.0
|
99
|
-
railties (3.2.0
|
100
|
-
actionpack (= 3.2.0
|
101
|
-
activesupport (= 3.2.0
|
95
|
+
railties (= 3.2.0)
|
96
|
+
railties (3.2.0)
|
97
|
+
actionpack (= 3.2.0)
|
98
|
+
activesupport (= 3.2.0)
|
102
99
|
rack-ssl (~> 1.3.2)
|
103
100
|
rake (>= 0.8.7)
|
104
101
|
rdoc (~> 3.4)
|
@@ -135,7 +132,6 @@ DEPENDENCIES
|
|
135
132
|
database_cleaner!
|
136
133
|
factory_girl_rails
|
137
134
|
guard-rspec
|
138
|
-
jquery-rails
|
139
135
|
libnotify
|
140
136
|
mysql2
|
141
137
|
rb-fsevent
|
data/README.rdoc
CHANGED
@@ -12,7 +12,7 @@ In your Gemfile
|
|
12
12
|
|
13
13
|
gem 'acts_as_defaultable'
|
14
14
|
|
15
|
-
Currently is tested on rails3.2.0.rc1, ruby 1.9.3 and mysql
|
15
|
+
Currently is tested on rails3.2.0.rc1, rails3.2.0.rc2, ruby 1.9.3 and mysql
|
16
16
|
|
17
17
|
== Example
|
18
18
|
|
@@ -29,6 +29,8 @@ Currently is tested on rails3.2.0.rc1, ruby 1.9.3 and mysql
|
|
29
29
|
uk.save
|
30
30
|
Country.default == gr # => false
|
31
31
|
|
32
|
+
If no options provived +default+ column is assumed.
|
33
|
+
|
32
34
|
== Notes
|
33
35
|
|
34
36
|
The option to acts_as_defaultable is the +column+ of the Model that defines default behaviour.
|
data/acts_as_defaultable.gemspec
CHANGED
@@ -20,13 +20,15 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ['lib']
|
21
21
|
#s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
|
22
22
|
|
23
|
-
s.add_dependency "rails", "
|
23
|
+
s.add_dependency "rails", "3.2.0"
|
24
24
|
|
25
|
-
s.add_development_dependency
|
25
|
+
s.add_development_dependency 'mysql2'
|
26
|
+
s.add_development_dependency 'rspec-rails'
|
26
27
|
s.add_development_dependency 'factory_girl_rails'
|
27
28
|
s.add_development_dependency 'spork', '0.9.0.rc9'
|
28
29
|
s.add_development_dependency 'rb-fsevent'
|
29
30
|
s.add_development_dependency 'guard-rspec'
|
30
31
|
s.add_development_dependency 'libnotify'
|
32
|
+
s.add_development_dependency 'database_cleaner'
|
31
33
|
|
32
34
|
end
|
data/lib/acts_as_defaultable.rb
CHANGED
@@ -8,7 +8,9 @@ module ActsAsDefaultable
|
|
8
8
|
|
9
9
|
after_save :set_unique_default
|
10
10
|
|
11
|
-
column
|
11
|
+
column = options.first.to_sym unless options.blank?
|
12
|
+
column ||= :default
|
13
|
+
|
12
14
|
puts "acts_as_defaultable: Specify a column #{column} in #{self.to_s}" unless self.column_names.include?(column.to_s)
|
13
15
|
|
14
16
|
if self.column_names.include?(column.to_s)
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,11 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
|
14
|
+
<<<<<<< HEAD
|
15
|
+
ActiveRecord::Schema.define(:version => 20120105110842) do
|
16
|
+
=======
|
17
|
+
ActiveRecord::Schema.define(:version => 20120104234100) do
|
18
|
+
>>>>>>> a78d85a48420ac87365e2329405c3644dc18a672
|
15
19
|
|
16
20
|
create_table "anothers", :force => true do |t|
|
17
21
|
t.string "test"
|
@@ -34,6 +38,13 @@ ActiveRecord::Schema.define(:version => 20120104140205) do
|
|
34
38
|
t.datetime "updated_at", :null => false
|
35
39
|
end
|
36
40
|
|
41
|
+
create_table "posts", :force => true do |t|
|
42
|
+
t.string "name"
|
43
|
+
t.integer "user_id"
|
44
|
+
t.datetime "created_at", :null => false
|
45
|
+
t.datetime "updated_at", :null => false
|
46
|
+
end
|
47
|
+
|
37
48
|
create_table "string_defaults", :force => true do |t|
|
38
49
|
t.string "name"
|
39
50
|
t.string "default"
|
@@ -41,4 +52,26 @@ ActiveRecord::Schema.define(:version => 20120104140205) do
|
|
41
52
|
t.datetime "updated_at", :null => false
|
42
53
|
end
|
43
54
|
|
55
|
+
<<<<<<< HEAD
|
56
|
+
create_table "users", :force => true do |t|
|
57
|
+
t.string "role"
|
58
|
+
t.string "name"
|
59
|
+
t.datetime "created_at", :null => false
|
60
|
+
t.datetime "updated_at", :null => false
|
61
|
+
end
|
62
|
+
|
63
|
+
create_table "without_cancans", :force => true do |t|
|
64
|
+
t.string "name"
|
65
|
+
t.integer "position"
|
66
|
+
t.datetime "created_at", :null => false
|
67
|
+
t.datetime "updated_at", :null => false
|
68
|
+
=======
|
69
|
+
create_table "test_defaults", :force => true do |t|
|
70
|
+
t.string "name"
|
71
|
+
t.boolean "default", :default => false
|
72
|
+
t.datetime "created_at", :null => false
|
73
|
+
t.datetime "updated_at", :null => false
|
74
|
+
>>>>>>> a78d85a48420ac87365e2329405c3644dc18a672
|
75
|
+
end
|
76
|
+
|
44
77
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TestDefault do
|
4
|
+
|
5
|
+
let(:one) { Factory.build(:td_one) }
|
6
|
+
let(:two) { Factory.build(:td_two) }
|
7
|
+
|
8
|
+
it 'should have a class method named default' do
|
9
|
+
TestDefault.respond_to?('default').should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have a default column definition' do
|
13
|
+
TestDefault.respond_to?('default_column').should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return the argument as the default column' do
|
17
|
+
TestDefault.default_column.should be_eql('default')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have a default positive value' do
|
21
|
+
TestDefault.default_positive_value.should be_eql(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have a default negative value' do
|
25
|
+
TestDefault.default_negative_value.should be_eql(false)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return nil if there is no default object' do
|
29
|
+
one.default = false
|
30
|
+
one.save
|
31
|
+
TestDefault.default.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return a default object' do
|
35
|
+
one.default = true
|
36
|
+
one.save
|
37
|
+
TestDefault.default.should be_eql(one)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set unique default object' do
|
41
|
+
two.default = true
|
42
|
+
two.save
|
43
|
+
one.default = true
|
44
|
+
two.save
|
45
|
+
TestDefault.default.should be_eql(two)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should return all defaults' do
|
49
|
+
one.default = true
|
50
|
+
one.save
|
51
|
+
two.default = true
|
52
|
+
two.save
|
53
|
+
TestDefault.all_defaults.size.should be_eql(1)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_defaultable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &22096320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - =
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.2.0
|
21
|
+
version: 3.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *22096320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mysql2
|
27
|
-
requirement: &
|
27
|
+
requirement: &22095620 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *22095620
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec-rails
|
38
|
+
requirement: &22094540 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *22094540
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: factory_girl_rails
|
38
|
-
requirement: &
|
49
|
+
requirement: &22195660 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *22195660
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: spork
|
49
|
-
requirement: &
|
60
|
+
requirement: &22194460 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - =
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: 0.9.0.rc9
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *22194460
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rb-fsevent
|
60
|
-
requirement: &
|
71
|
+
requirement: &22193240 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *22193240
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: guard-rspec
|
71
|
-
requirement: &
|
82
|
+
requirement: &22191380 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,21 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *22191380
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: libnotify
|
82
|
-
requirement: &
|
93
|
+
requirement: &22189700 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *22189700
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: database_cleaner
|
104
|
+
requirement: &22188840 !ruby/object:Gem::Requirement
|
83
105
|
none: false
|
84
106
|
requirements:
|
85
107
|
- - ! '>='
|
@@ -87,7 +109,7 @@ dependencies:
|
|
87
109
|
version: '0'
|
88
110
|
type: :development
|
89
111
|
prerelease: false
|
90
|
-
version_requirements: *
|
112
|
+
version_requirements: *22188840
|
91
113
|
description: This 'acts_as' extension provides the capability for having a default
|
92
114
|
object. The class that has this specified needs to have a default column defined
|
93
115
|
as an integer, string or boolean on the mapped database table
|
@@ -121,6 +143,7 @@ files:
|
|
121
143
|
- spec/dummy/app/models/boolean_default.rb
|
122
144
|
- spec/dummy/app/models/fail_one.rb
|
123
145
|
- spec/dummy/app/models/string_default.rb
|
146
|
+
- spec/dummy/app/models/test_default.rb
|
124
147
|
- spec/dummy/app/views/layouts/application.html.erb
|
125
148
|
- spec/dummy/config.ru
|
126
149
|
- spec/dummy/config/application.rb
|
@@ -142,6 +165,7 @@ files:
|
|
142
165
|
- spec/dummy/db/migrate/20120104112622_create_fail_ones.rb
|
143
166
|
- spec/dummy/db/migrate/20120104135210_create_boolean_defaults.rb
|
144
167
|
- spec/dummy/db/migrate/20120104140205_create_string_defaults.rb
|
168
|
+
- spec/dummy/db/migrate/20120104234100_create_test_defaults.rb
|
145
169
|
- spec/dummy/db/schema.rb
|
146
170
|
- spec/dummy/lib/assets/.gitkeep
|
147
171
|
- spec/dummy/log/.gitkeep
|
@@ -154,10 +178,12 @@ files:
|
|
154
178
|
- spec/factories/boolean_default.rb
|
155
179
|
- spec/factories/fail_one.rb
|
156
180
|
- spec/factories/string_default.rb
|
181
|
+
- spec/factories/test_default.rb
|
157
182
|
- spec/models/another_spec.rb
|
158
183
|
- spec/models/boolean_default_spec.rb
|
159
184
|
- spec/models/fail_one_spec.rb
|
160
185
|
- spec/models/string_default_spec.rb
|
186
|
+
- spec/models/test_default_spec.rb
|
161
187
|
- spec/spec_helper.rb
|
162
188
|
homepage: https://github.com/chief/acts_as_defaultable
|
163
189
|
licenses: []
|
@@ -173,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
199
|
version: '0'
|
174
200
|
segments:
|
175
201
|
- 0
|
176
|
-
hash:
|
202
|
+
hash: -1161643751702136176
|
177
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
204
|
none: false
|
179
205
|
requirements:
|
@@ -182,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
208
|
version: '0'
|
183
209
|
segments:
|
184
210
|
- 0
|
185
|
-
hash:
|
211
|
+
hash: -1161643751702136176
|
186
212
|
requirements: []
|
187
213
|
rubyforge_project:
|
188
214
|
rubygems_version: 1.8.10
|