multi_bit_field 0.0.1 → 0.0.2
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.markdown +54 -12
- data/lib/multi_bit_field/version.rb +1 -1
- data/lib/multi_bit_field.rb +132 -15
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +16 -0
- data/test/dummy/log/test.log +968 -0
- data/test/multi_bit_field_test.rb +109 -3
- metadata +14 -8
@@ -3,7 +3,7 @@ require 'minitest_helper'
|
|
3
3
|
describe MultiBitField do
|
4
4
|
#
|
5
5
|
# class Person < ActiveRecord::Base
|
6
|
-
# has_bit_fields :birthday, 0..3 =>
|
6
|
+
# has_bit_fields :birthday, :month => 0..3, :day => 4..8
|
7
7
|
# end
|
8
8
|
#
|
9
9
|
describe "class methods" do
|
@@ -13,8 +13,24 @@ describe MultiBitField do
|
|
13
13
|
|
14
14
|
let(:bitfields) { {:birthday => 9} }
|
15
15
|
|
16
|
-
it "implements a
|
17
|
-
subject.
|
16
|
+
it "implements a bitfield_size method" do
|
17
|
+
subject.bitfield_size(:birthday).must_equal 9
|
18
|
+
end
|
19
|
+
|
20
|
+
it "implement reset_mask_for with single field" do
|
21
|
+
subject.reset_mask_for(:birthday, :month).must_equal 31
|
22
|
+
end
|
23
|
+
|
24
|
+
it "implements reset_mask_for with multiple fields" do
|
25
|
+
subject.reset_mask_for(:birthday, :month, :day).must_equal 0
|
26
|
+
end
|
27
|
+
|
28
|
+
it "implements increment_mask_for with single field" do
|
29
|
+
subject.increment_mask_for(:birthday, :month).must_equal 32
|
30
|
+
end
|
31
|
+
|
32
|
+
it "implements increment_mask_for with multiple fields" do
|
33
|
+
subject.increment_mask_for(:birthday, :month, :day).must_equal 33
|
18
34
|
end
|
19
35
|
|
20
36
|
end
|
@@ -78,4 +94,94 @@ describe MultiBitField do
|
|
78
94
|
end
|
79
95
|
end
|
80
96
|
|
97
|
+
describe "resetting a single bitfield" do
|
98
|
+
subject do
|
99
|
+
Person.create :month => 12, :day => 25
|
100
|
+
end
|
101
|
+
|
102
|
+
after do
|
103
|
+
Person.destroy_all
|
104
|
+
end
|
105
|
+
|
106
|
+
it "resets a single field to 0" do
|
107
|
+
subject.reset_bitfield :birthday, :month
|
108
|
+
subject.reload
|
109
|
+
subject.month.must_equal 0
|
110
|
+
subject.day.must_equal 25
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "resetting multiple bitfields" do
|
115
|
+
subject do
|
116
|
+
Person.create :month => 6, :day => 15
|
117
|
+
end
|
118
|
+
|
119
|
+
after do
|
120
|
+
Person.destroy_all
|
121
|
+
end
|
122
|
+
|
123
|
+
it "resets both fields to 0" do
|
124
|
+
subject.reset_bitfields :birthday, :month, :day
|
125
|
+
subject.reload
|
126
|
+
subject.month.must_equal 0
|
127
|
+
subject.day.must_equal 0
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "resetting bitfields in batch" do
|
132
|
+
before do
|
133
|
+
Person.create :month => 6, :day => 15
|
134
|
+
Person.create :month => 2, :day => 28
|
135
|
+
Person.reset_bitfield :birthday, :month
|
136
|
+
end
|
137
|
+
|
138
|
+
after do
|
139
|
+
Person.destroy_all
|
140
|
+
end
|
141
|
+
|
142
|
+
it "resets field in all models to 0" do
|
143
|
+
Person.all.map(&:month).must_equal [0, 0]
|
144
|
+
end
|
145
|
+
|
146
|
+
it "keeps other field in all models at previous value" do
|
147
|
+
Person.all.map(&:day).must_equal [15, 28]
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "incrementing bitfields" do
|
152
|
+
subject do
|
153
|
+
Person.create :month => 6, :day => 15
|
154
|
+
end
|
155
|
+
|
156
|
+
after do
|
157
|
+
Person.destroy_all
|
158
|
+
end
|
159
|
+
|
160
|
+
it "increments both bitfields" do
|
161
|
+
subject.increment_bitfields :birthday, :month, :day
|
162
|
+
subject.reload
|
163
|
+
subject.month.must_equal 7
|
164
|
+
subject.day.must_equal 16
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "resetting bitfields in batch" do
|
169
|
+
before do
|
170
|
+
Person.create :month => 6, :day => 15
|
171
|
+
Person.create :month => 2, :day => 28
|
172
|
+
Person.increment_bitfield :birthday, :month
|
173
|
+
end
|
174
|
+
|
175
|
+
after do
|
176
|
+
Person.destroy_all
|
177
|
+
end
|
178
|
+
|
179
|
+
it "resets field in all models to 0" do
|
180
|
+
Person.all.map(&:month).must_equal [7, 3]
|
181
|
+
end
|
182
|
+
|
183
|
+
it "keeps other field in all models at previous value" do
|
184
|
+
Person.all.map(&:day).must_equal [15, 28]
|
185
|
+
end
|
186
|
+
end
|
81
187
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_bit_field
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-03 00:00:00.000000000 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &70267352364720 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.2.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70267352364720
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sqlite3
|
28
|
-
requirement: &
|
28
|
+
requirement: &70267352364300 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70267352364300
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: minitest
|
39
|
-
requirement: &
|
39
|
+
requirement: &70267352363840 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70267352363840
|
48
48
|
description: ''
|
49
49
|
email:
|
50
50
|
- spiegela@gmail.com
|
@@ -111,12 +111,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
111
|
- - ! '>='
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: 2105517145029265956
|
114
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
118
|
none: false
|
116
119
|
requirements:
|
117
120
|
- - ! '>='
|
118
121
|
- !ruby/object:Gem::Version
|
119
122
|
version: '0'
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
hash: 2105517145029265956
|
120
126
|
requirements: []
|
121
127
|
rubyforge_project:
|
122
128
|
rubygems_version: 1.6.2
|