has_many_booleans 0.9.1 → 0.9.3
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/README.rdoc +5 -0
- data/Rakefile +1 -1
- data/lib/has_many_booleans.rb +48 -9
- data/test/debug.log +16494 -631
- data/test/has_many_booleans_plugin.sqlite3 +0 -0
- data/test/has_many_booleans_test.rb +29 -10
- data/test/schema.rb +8 -1
- metadata +9 -4
Binary file
|
@@ -107,6 +107,10 @@ class HasManyBooleansTest < ActiveSupport::TestCase
|
|
107
107
|
has_many_booleans :name, :password, :admin, :false_values => ["super", 'toll', 3]
|
108
108
|
end
|
109
109
|
|
110
|
+
class UnknownValue < ActiveRecord::Base
|
111
|
+
has_many_booleans :name, :password, :admin, :unkown_value => false
|
112
|
+
end
|
113
|
+
|
110
114
|
class Scope < ActiveRecord::Base
|
111
115
|
has_many_booleans :name, :password, :admin, :self => true
|
112
116
|
end
|
@@ -133,8 +137,8 @@ class HasManyBooleansTest < ActiveSupport::TestCase
|
|
133
137
|
:ar_callback => ArCallback.new,
|
134
138
|
:lazy_false => LazyFalse.new,
|
135
139
|
:false_value => FalseValue.new,
|
140
|
+
:unknown_value => UnknownValue.new,
|
136
141
|
}
|
137
|
-
@booleans_options = Hash[ @instances.map{|k,v| [k, v.class.booleans_options]} ]
|
138
142
|
end
|
139
143
|
|
140
144
|
def create_instance(which, *params)
|
@@ -143,12 +147,9 @@ class HasManyBooleansTest < ActiveSupport::TestCase
|
|
143
147
|
end
|
144
148
|
|
145
149
|
def loop_instances(with_assign = false)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
loop{
|
150
|
-
@n, @a = cur_actions.next # name, instances
|
151
|
-
@o = cur_booleans_options.next[1] # booleans_options
|
150
|
+
@instances.each{ |name, instance|
|
151
|
+
@n, @a = name, instance
|
152
|
+
@o = @a.class.booleans_options
|
152
153
|
next if with_assign &&( !@o[:suffixes].include?('=') || !@o[:append] || @o[:append].empty?) # or name does not work (existing method overwrite protection)
|
153
154
|
yield
|
154
155
|
}
|
@@ -214,7 +215,7 @@ class HasManyBooleansTest < ActiveSupport::TestCase
|
|
214
215
|
test 'set and unset (with =)' do
|
215
216
|
create_instances and loop_instances(true) do
|
216
217
|
( snd :name, '=', false )#, "#{@a.class},#{p :O;snd :name, '=', false}"
|
217
|
-
assert_not snd :name
|
218
|
+
assert_not (snd :name), "#{@a}, #{snd :name}"
|
218
219
|
snd :name, '=', true
|
219
220
|
assert snd :name
|
220
221
|
|
@@ -232,14 +233,14 @@ class HasManyBooleansTest < ActiveSupport::TestCase
|
|
232
233
|
assert @a.save
|
233
234
|
tmp = @a.class
|
234
235
|
|
235
|
-
assert_instance_of @a = @a.class.last
|
236
|
+
assert_instance_of tmp, (@a = @a.class.last)
|
236
237
|
assert_not snd what
|
237
238
|
|
238
239
|
snd what, '=', true
|
239
240
|
assert @a.save
|
240
241
|
tmp = @a.class
|
241
242
|
|
242
|
-
assert_instance_of @a = @a.class.last
|
243
|
+
assert_instance_of tmp, (@a = @a.class.last)
|
243
244
|
assert snd what
|
244
245
|
}
|
245
246
|
end
|
@@ -268,6 +269,14 @@ class HasManyBooleansTest < ActiveSupport::TestCase
|
|
268
269
|
assert_equal @a.name, 'matz'
|
269
270
|
end
|
270
271
|
|
272
|
+
test 'Model.new works' do
|
273
|
+
@a = ArCallback.new :name_activated => true, :name => 'Hildegard', :password => '123'
|
274
|
+
|
275
|
+
assert @a.name_activated
|
276
|
+
assert_equal @a.name, 'Yukihiro'
|
277
|
+
assert_equal @a.password, '123'
|
278
|
+
end
|
279
|
+
|
271
280
|
# # #
|
272
281
|
# booleans_options
|
273
282
|
#
|
@@ -345,6 +354,16 @@ class HasManyBooleansTest < ActiveSupport::TestCase
|
|
345
354
|
assert snd :name
|
346
355
|
end
|
347
356
|
|
357
|
+
# test "unknown value" do
|
358
|
+
# create_instance UnknownValue
|
359
|
+
|
360
|
+
# snd :name, '=', true
|
361
|
+
# snd :name, '=', 'not in true values'
|
362
|
+
# assert_not snd :name
|
363
|
+
# snd :name, '=', 'true'
|
364
|
+
# assert snd :name
|
365
|
+
# end
|
366
|
+
|
348
367
|
# scopes
|
349
368
|
test 'scopes' do
|
350
369
|
# create dummy data
|
data/test/schema.rb
CHANGED
@@ -13,12 +13,12 @@ ActiveRecord::Schema.define(:version => 0) do
|
|
13
13
|
selves
|
14
14
|
self_append_nils
|
15
15
|
self_names
|
16
|
-
ar_callbacks
|
17
16
|
lazy_falses
|
18
17
|
booleans_as_hashes
|
19
18
|
single_hashes
|
20
19
|
validate_tests
|
21
20
|
false_values
|
21
|
+
unknown_values
|
22
22
|
scopes
|
23
23
|
|.each do |table_name|
|
24
24
|
create_table table_name, :force => true do |t|
|
@@ -32,5 +32,12 @@ ActiveRecord::Schema.define(:version => 0) do
|
|
32
32
|
t.integer :bools
|
33
33
|
end
|
34
34
|
|
35
|
+
create_table 'ar_callbacks', :force => true do |t|
|
36
|
+
t.string :name
|
37
|
+
t.string :password
|
38
|
+
t.integer :booleans
|
39
|
+
end
|
40
|
+
|
41
|
+
|
35
42
|
end
|
36
43
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_many_booleans
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 61
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
9
|
+
- 3
|
10
|
+
version: 0.9.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jan Lelis
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-23 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -52,23 +53,27 @@ rdoc_options: []
|
|
52
53
|
require_paths:
|
53
54
|
- lib
|
54
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
55
57
|
requirements:
|
56
58
|
- - ">="
|
57
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
58
61
|
segments:
|
59
62
|
- 0
|
60
63
|
version: "0"
|
61
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
62
66
|
requirements:
|
63
67
|
- - ">="
|
64
68
|
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
65
70
|
segments:
|
66
71
|
- 0
|
67
72
|
version: "0"
|
68
73
|
requirements: []
|
69
74
|
|
70
75
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.3.
|
76
|
+
rubygems_version: 1.3.7
|
72
77
|
signing_key:
|
73
78
|
specification_version: 3
|
74
79
|
summary: This Rails plugin/gem allows you to generate virtual boolean attributes, which get saved in the database as a single bitset integer
|