degu 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c7ff2eaa04adad080028fead220da2f01df66cf
4
- data.tar.gz: 6273045fdce4f22cb41e6d3260af9f6bd801cf07
3
+ metadata.gz: 6d11ad3d30e696815259b126d84c4b22fcc34972
4
+ data.tar.gz: 429c99d88ae9bd7d151064ff80a031846fc4ca61
5
5
  SHA512:
6
- metadata.gz: ab52b10983dea4a5a8033624b0cffdc74a2fdce9b6af3b0ae6d7e30c1b9ff7de1a63be0b69a0664191112552e86d410be79d5d962de8e52af6c72b548f941bf1
7
- data.tar.gz: 0afb37cf14e0700c3407c6da137cb1b454184b6de4b347baac5f214a9c5fba598084245eef6c1405f30aef7ddc53e4acd5b3a425951b39e58229a5c15b809e74
6
+ metadata.gz: 49a820e95b6e154a83ba14c35bac7121ed83cba626fecd7e704c8b34ad21b80fa521b134a4b6c349ecfedc2c53524d1940fb715f2bd70c806d95abf038678c71
7
+ data.tar.gz: c0bf803c5398e823312fd83996ff4b51d4f396e41c6a0831e1922abcdc868a929bdfcef38c01e183d616aa8303112de7c055ed54c8a4339841e298d6965d3cac
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  .*.sw[pon]
2
+ .AppleDouble
2
3
  .DS_Store
4
+ .bundle
3
5
  .ruby-gemset
4
6
  .ruby-version
5
7
  .rvmrc
data/.travis.yml CHANGED
@@ -3,22 +3,16 @@ bundler_args: --binstubs
3
3
 
4
4
  # Specify which ruby versions you wish to run your tests on, each version will be used
5
5
  rvm:
6
- - 1.8.7
7
- - 1.9.2
8
6
  - 1.9.3
9
7
  - 2.0.0
10
- - rbx-18mode
8
+ - 2.1.2
11
9
  - rbx-19mode
12
- - ree
13
- - jruby-18mode
14
10
  - jruby-19mode
15
11
  - ruby-head
16
12
  matrix:
17
13
  allow_failures:
18
- - rvm: jruby-18mode
19
14
  - rvm: jruby-19mode
20
- - rvm: rbx-18mode
21
15
  - rvm: rbx-19mode
22
- - rvm: ruby-head #https://github.com/travis-ci/travis-ci/issues/1195
16
+ - rvm: ruby-head
23
17
 
24
18
  script: "bundle exec rake"
data/Rakefile CHANGED
@@ -13,15 +13,17 @@ GemHadar do
13
13
  test_dir 'test'
14
14
  test_files Dir['test/**/*_test.rb']
15
15
  spec_dir 'spec'
16
- ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage', '.DS_Store', '.ruby-gemset', '.ruby-version'
16
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage',
17
+ '.DS_Store', '.ruby-gemset', '.ruby-version', '.bundle', '.AppleDouble'
18
+
17
19
  readme 'README.md'
18
20
 
19
21
  dependency 'activerecord', '>= 3.0', '< 5.0'
20
22
 
23
+ development_dependency 'test-unit'
21
24
  development_dependency 'mocha'
22
25
  development_dependency 'sqlite3'
23
26
  development_dependency 'rspec'
24
- development_dependency 'utils'
25
27
  end
26
28
 
27
29
  desc 'Run specs and tests'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/degu.gemspec CHANGED
@@ -1,20 +1,21 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # stub: degu 0.5.0 ruby lib
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "degu"
5
- s.version = "0.4.0"
6
+ s.version = "0.5.0"
6
7
 
7
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
8
10
  s.authors = ["Florian Frank"]
9
- s.date = "2013-07-11"
11
+ s.date = "2014-06-10"
10
12
  s.description = "Library that includes enums, and rails support for enums and bitfield sets."
11
13
  s.email = "dev@pkw.de"
12
14
  s.extra_rdoc_files = ["README.md", "lib/degu.rb", "lib/degu/has_enum.rb", "lib/degu/has_set.rb", "lib/degu/polite.rb", "lib/degu/renum.rb", "lib/degu/renum/enumerated_value.rb", "lib/degu/renum/enumerated_value_type_factory.rb", "lib/degu/rude.rb", "lib/degu/version.rb"]
13
15
  s.files = [".gitignore", ".travis.yml", "COPYING", "Gemfile", "README.md", "Rakefile", "VERSION", "degu.gemspec", "lib/degu.rb", "lib/degu/has_enum.rb", "lib/degu/has_set.rb", "lib/degu/polite.rb", "lib/degu/renum.rb", "lib/degu/renum/enumerated_value.rb", "lib/degu/renum/enumerated_value_type_factory.rb", "lib/degu/rude.rb", "lib/degu/version.rb", "spec/renum_spec.rb", "spec/spec_helper.rb", "test/has_enum_test.rb", "test/has_set_test.rb", "test/test_helper.rb", "test_helper.rb"]
14
16
  s.homepage = "https://github.com/tuskenraiders/degu"
15
17
  s.rdoc_options = ["--title", "Degu - Library for enums and bitfield sets.", "--main", "README.md"]
16
- s.require_paths = ["lib"]
17
- s.rubygems_version = "2.0.4"
18
+ s.rubygems_version = "2.2.1"
18
19
  s.summary = "Library for enums and bitfield sets."
19
20
  s.test_files = ["test/has_enum_test.rb", "test/has_set_test.rb"]
20
21
 
@@ -22,26 +23,26 @@ Gem::Specification.new do |s|
22
23
  s.specification_version = 4
23
24
 
24
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
- s.add_development_dependency(%q<gem_hadar>, ["~> 0.1.8"])
26
+ s.add_development_dependency(%q<gem_hadar>, ["~> 1.0.0"])
27
+ s.add_development_dependency(%q<test-unit>, [">= 0"])
26
28
  s.add_development_dependency(%q<mocha>, [">= 0"])
27
29
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
28
30
  s.add_development_dependency(%q<rspec>, [">= 0"])
29
- s.add_development_dependency(%q<utils>, [">= 0"])
30
31
  s.add_runtime_dependency(%q<activerecord>, ["< 5.0", ">= 3.0"])
31
32
  else
32
- s.add_dependency(%q<gem_hadar>, ["~> 0.1.8"])
33
+ s.add_dependency(%q<gem_hadar>, ["~> 1.0.0"])
34
+ s.add_dependency(%q<test-unit>, [">= 0"])
33
35
  s.add_dependency(%q<mocha>, [">= 0"])
34
36
  s.add_dependency(%q<sqlite3>, [">= 0"])
35
37
  s.add_dependency(%q<rspec>, [">= 0"])
36
- s.add_dependency(%q<utils>, [">= 0"])
37
38
  s.add_dependency(%q<activerecord>, ["< 5.0", ">= 3.0"])
38
39
  end
39
40
  else
40
- s.add_dependency(%q<gem_hadar>, ["~> 0.1.8"])
41
+ s.add_dependency(%q<gem_hadar>, ["~> 1.0.0"])
42
+ s.add_dependency(%q<test-unit>, [">= 0"])
41
43
  s.add_dependency(%q<mocha>, [">= 0"])
42
44
  s.add_dependency(%q<sqlite3>, [">= 0"])
43
45
  s.add_dependency(%q<rspec>, [">= 0"])
44
- s.add_dependency(%q<utils>, [">= 0"])
45
46
  s.add_dependency(%q<activerecord>, ["< 5.0", ">= 3.0"])
46
47
  end
47
48
  end
data/lib/degu/has_set.rb CHANGED
@@ -31,11 +31,11 @@ module Degu
31
31
  value |= 1 << set_element.bitfield_index
32
32
  end
33
33
  end
34
- write_attribute set_column, value
34
+ write_set_attribute set_column, value
35
35
  end
36
36
 
37
37
  define_method(set_name) do
38
- value = read_attribute(set_column) or return
38
+ value = read_set_attribute(set_column) or return
39
39
  set_elements = enum_class.select do |enum_element|
40
40
  mask = 1 << enum_element.bitfield_index
41
41
  value & mask == mask
@@ -61,25 +61,53 @@ module Degu
61
61
  enum_class.each do |enum|
62
62
  define_method("#{set_name_singular}_#{enum.underscored_name}?") do
63
63
  mask = 1 << enum.bitfield_index
64
- read_attribute(set_column) & mask == mask
64
+ read_set_attribute(set_column) & mask == mask
65
65
  end
66
66
 
67
67
  alias_method :"#{set_name_singular}_#{enum.underscored_name}", :"#{set_name_singular}_#{enum.underscored_name}?"
68
68
 
69
69
  define_method("#{set_name_singular}_#{enum.underscored_name}=") do |true_or_false|
70
70
  mask = 1 << enum.bitfield_index
71
- total_value = read_attribute(set_column)
71
+ total_value = read_set_attribute(set_column)
72
72
  current_value = mask & total_value == mask
73
73
  true_or_false = true if true_or_false.to_s == "true" || true_or_false.respond_to?(:to_i) && true_or_false.to_i == 1
74
74
  true_or_false = false if true_or_false.to_s == "false" || true_or_false.respond_to?(:to_i) && true_or_false.to_i == 0
75
75
  if current_value != true_or_false
76
- write_attribute set_column, true_or_false ? total_value | mask : total_value & ~mask
76
+ write_set_attribute set_column, true_or_false ? total_value | mask : total_value & ~mask
77
77
  end
78
78
  end
79
79
  end
80
80
  end
81
81
  end
82
82
 
83
+ ##
84
+ # Just a small wrapper about the `ActiveRecord::Base#read_attribute` method, which also checks the type
85
+ # of the column and converts the value to an `Integer` if `String` is given.
86
+ def read_set_attribute(attribute_name)
87
+ value = read_attribute(attribute_name)
88
+ column_type = ((column_definition = self.class.columns_hash[attribute_name.to_s]) and column_definition.type)
89
+ value = value.to_i(10) if column_type == :string
90
+ value
91
+ end
92
+
93
+ ##
94
+ # Just a small wrapper about the `ActiveRecord::Base#write_attribute` method, which also checks the type
95
+ # of the column and converts the value to an `String` if `String` is the column type. This is needed because
96
+ # implicit conversion produces something like `3.4532454354325645e+17` instead of an `integer`
97
+ def write_set_attribute(attribute_name, value)
98
+ column_type = ((column_definition = self.class.columns_hash[attribute_name.to_s]) and column_definition.type)
99
+ value = value.to_s(10) if column_type == :string
100
+ write_attribute(attribute_name, value)
101
+ end
102
+
103
+ ##
104
+ # Understands the arguments as the list of enum values
105
+ # The argument value can be
106
+ # - a `string` of enum values joined by a comma
107
+ # - an enum constant
108
+ # - a `symbol` which resolves to the enum constant
109
+ # - an `integer` as the index of the enum class
110
+ # If you have just 1 value, you do not need to enclose it in an `Array`
83
111
  def has_set_coerce_argument_value(enum_class, argument_value)
84
112
  invalid_set_elements = []
85
113
  set_elements =
data/lib/degu/renum.rb CHANGED
@@ -9,7 +9,7 @@ module Degu
9
9
  # Figures out whether the new enumeration will live in Object or the
10
10
  # receiving Module, then delegates to EnumeratedValueTypeFactory#create for
11
11
  # all the real work.
12
- def enum(type_name, values = :defined_in_block, &block)
12
+ def renum(type_name, values = :defined_in_block, &block)
13
13
  nest = self.is_a?(Module) ? self : Object
14
14
  EnumeratedValueTypeFactory.create(nest, type_name, values, &block)
15
15
  end
data/lib/degu/rude.rb CHANGED
@@ -3,6 +3,9 @@ end
3
3
  require 'degu/polite'
4
4
  class Object
5
5
  include Degu::Renum
6
+ unless defined?(enum)
7
+ alias_method :enum, :renum
8
+ end
6
9
  end
7
10
  if defined?(ActiveRecord::Base)
8
11
  class ActiveRecord::Base
data/lib/degu/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Degu
2
2
  # Degu version
3
- VERSION = '0.4.0'
4
- VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
3
+ VERSION = '0.5.0'
4
+ VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
7
7
  VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
data/spec/renum_spec.rb CHANGED
@@ -4,75 +4,79 @@ enum :Status, [ :NOT_STARTED, :IN_PROGRESS, :COMPLETE ]
4
4
 
5
5
  enum :Fuzzy, [ :FooBar, :BarFoo ]
6
6
 
7
+ class RenumNameTest < ActiveRecord::Base
8
+ renum :RenumTest, [ :Foo, :Bar ]
9
+ end
10
+
7
11
  describe "basic enum" do
8
12
 
9
13
  it "creates a class for the value type" do
10
- Status.should be_an_instance_of(Class)
14
+ expect(Status).to be_an_instance_of(Class)
11
15
  end
12
16
 
13
17
  it "makes each value an instance of the value type" do
14
- Status::NOT_STARTED.should be_an_instance_of(Status)
18
+ expect(Status::NOT_STARTED).to be_an_instance_of(Status)
15
19
  end
16
20
 
17
21
  it "exposes array of values" do
18
- Status.values.should == [Status::NOT_STARTED, Status::IN_PROGRESS, Status::COMPLETE]
19
- Status.all.should == [Status::NOT_STARTED, Status::IN_PROGRESS, Status::COMPLETE]
22
+ expect(Status.values).to eq [Status::NOT_STARTED, Status::IN_PROGRESS, Status::COMPLETE]
23
+ expect(Status.all).to eq [Status::NOT_STARTED, Status::IN_PROGRESS, Status::COMPLETE]
20
24
  end
21
25
 
22
26
  it "groks first and last to retreive value" do
23
- Status.first.should == Status::NOT_STARTED
24
- Status.last.should == Status::COMPLETE
27
+ expect(Status.first).to eq Status::NOT_STARTED
28
+ expect(Status.last).to eq Status::COMPLETE
25
29
  end
26
30
 
27
31
  it "enumerates over values" do
28
- Status.map {|s| s.name}.should == %w[NOT_STARTED IN_PROGRESS COMPLETE]
32
+ expect(Status.map { |s| s.name }).to eq %w[NOT_STARTED IN_PROGRESS COMPLETE]
29
33
  end
30
34
 
31
35
  it "indexes values" do
32
- Status[2].should == Status::COMPLETE
33
- Color[0].should == Color::RED
34
- Status['2'].should == Status::COMPLETE
35
- Color['0'].should == Color::RED
36
+ expect(Status[2]).to eq Status::COMPLETE
37
+ expect(Color[0]).to eq Color::RED
38
+ expect(Status['2']).to eq Status::COMPLETE
39
+ expect(Color['0']).to eq Color::RED
36
40
  end
37
41
 
38
42
  it "provides index lookup on values" do
39
- Status::IN_PROGRESS.index.should == 1
40
- Color::GREEN.index.should == 1
43
+ expect(Status::IN_PROGRESS.index).to eq 1
44
+ expect(Color::GREEN.index).to eq 1
41
45
  end
42
46
 
43
47
  it "provides an id on values" do
44
- Status::IN_PROGRESS.id.should == 1
45
- Color::GREEN.id.should == 1
48
+ expect(Status::IN_PROGRESS.id).to eq 1
49
+ expect(Color::GREEN.id).to eq 1
46
50
  end
47
51
 
48
52
 
49
53
  it "provides name lookup on values" do
50
- Status.with_name('IN_PROGRESS').should == Status::IN_PROGRESS
51
- Color.with_name('GREEN').should == Color::GREEN
52
- Color.with_name('IN_PROGRESS').should be_nil
54
+ expect(Status.with_name('IN_PROGRESS')).to eq Status::IN_PROGRESS
55
+ expect(Color.with_name('GREEN')).to eq Color::GREEN
56
+ expect(Color.with_name('IN_PROGRESS')).to be_nil
53
57
  end
54
58
 
55
59
  it "provides fuzzy name lookup on values" do
56
- Fuzzy[0].should == Fuzzy::FooBar
57
- Fuzzy[1].should == Fuzzy::BarFoo
58
- Fuzzy[:FooBar].should == Fuzzy::FooBar
59
- Fuzzy[:BarFoo].should == Fuzzy::BarFoo
60
- Fuzzy['FooBar'].should == Fuzzy::FooBar
61
- Fuzzy['BarFoo'].should == Fuzzy::BarFoo
62
- Fuzzy[:foo_bar].should == Fuzzy::FooBar
63
- Fuzzy[:bar_foo].should == Fuzzy::BarFoo
64
- Fuzzy['foo_bar'].should == Fuzzy::FooBar
65
- Fuzzy['bar_foo'].should == Fuzzy::BarFoo
66
- Fuzzy[Fuzzy::FooBar].should == Fuzzy::FooBar
67
- Fuzzy[Fuzzy::BarFoo].should == Fuzzy::BarFoo
60
+ expect(Fuzzy[0]).to eq Fuzzy::FooBar
61
+ expect(Fuzzy[1]).to eq Fuzzy::BarFoo
62
+ expect(Fuzzy[:FooBar]).to eq Fuzzy::FooBar
63
+ expect(Fuzzy[:BarFoo]).to eq Fuzzy::BarFoo
64
+ expect(Fuzzy['FooBar']).to eq Fuzzy::FooBar
65
+ expect(Fuzzy['BarFoo']).to eq Fuzzy::BarFoo
66
+ expect(Fuzzy[:foo_bar]).to eq Fuzzy::FooBar
67
+ expect(Fuzzy[:bar_foo]).to eq Fuzzy::BarFoo
68
+ expect(Fuzzy['foo_bar']).to eq Fuzzy::FooBar
69
+ expect(Fuzzy['bar_foo']).to eq Fuzzy::BarFoo
70
+ expect(Fuzzy[Fuzzy::FooBar]).to eq Fuzzy::FooBar
71
+ expect(Fuzzy[Fuzzy::BarFoo]).to eq Fuzzy::BarFoo
68
72
  end
69
73
 
70
74
  it "provides a reasonable to_s for values" do
71
- Status::NOT_STARTED.to_s.should == "Status::NOT_STARTED"
75
+ expect(Status::NOT_STARTED.to_s).to eq "Status::NOT_STARTED"
72
76
  end
73
77
 
74
78
  it "makes values comparable" do
75
- Color::RED.should < Color::GREEN
79
+ expect(Color::RED).to be < Color::GREEN
76
80
  end
77
81
  end
78
82
 
@@ -82,7 +86,7 @@ end
82
86
 
83
87
  describe "nested enum" do
84
88
  it "is namespaced in the containing module or class" do
85
- MyNamespace::FooValue::Bar.class.should == MyNamespace::FooValue
89
+ expect(MyNamespace::FooValue::Bar.class).to eq MyNamespace::FooValue
86
90
  end
87
91
  end
88
92
 
@@ -94,7 +98,7 @@ end
94
98
 
95
99
  describe "enum with a block" do
96
100
  it "can define additional instance methods" do
97
- Color::RED.abbr.should == "R"
101
+ expect(Color::RED.abbr).to eq "R"
98
102
  end
99
103
  end
100
104
 
@@ -119,11 +123,11 @@ end
119
123
 
120
124
  describe "enum with no values array and values declared in the block" do
121
125
  it "provides another way to declare values where an init method can take extra params" do
122
- Size::Small.description.should == "Really really tiny"
126
+ expect(Size::Small.description).to eq "Really really tiny"
123
127
  end
124
128
 
125
129
  it "works the same as the basic form with respect to ordering" do
126
- Size.values.should == [Size::Small, Size::Medium, Size::Large, Size::Unknown]
130
+ expect(Size.values).to eq [Size::Small, Size::Medium, Size::Large, Size::Unknown]
127
131
  end
128
132
 
129
133
  it "responds as expected to arbitrary method calls, in spite of using method_missing for value definition" do
@@ -131,11 +135,11 @@ describe "enum with no values array and values declared in the block" do
131
135
  end
132
136
 
133
137
  it "supports there being no extra data and no init() method defined, if you don't need them" do
134
- HairColor::BLONDE.name.should == "BLONDE"
138
+ expect(HairColor::BLONDE.name).to eq "BLONDE"
135
139
  end
136
140
 
137
141
  it "calls the init method even if no arguments are provided" do
138
- Size::Unknown.description.should == "NO DESCRIPTION GIVEN"
142
+ expect(Size::Unknown.description).to eq "NO DESCRIPTION GIVEN"
139
143
  end
140
144
  end
141
145
 
@@ -165,8 +169,8 @@ end
165
169
 
166
170
  describe "an enum with instance-specific method definitions" do
167
171
  it "allows each instance to have its own behavior" do
168
- Rating::ThumbsDown.description.should == "real real bad"
169
- Rating::ThumbsUp.description.should == "so so good"
172
+ expect(Rating::ThumbsDown.description).to eq "real real bad"
173
+ expect(Rating::ThumbsUp.description).to eq "so so good"
170
174
  end
171
175
 
172
176
  it "uses the implementation given at the top level if no alternate definition is given for an instance" do
@@ -174,16 +178,16 @@ describe "an enum with instance-specific method definitions" do
174
178
  end
175
179
 
176
180
  it "allows definition of a method on just one instance" do
177
- Rating::ThumbsUp.thumbs_up_only_method.should == "this method is only defined on ThumbsUp"
181
+ expect(Rating::ThumbsUp.thumbs_up_only_method).to eq "this method is only defined on ThumbsUp"
178
182
  expect { Rating::NotRated.thumbs_up_only_method }.to raise_error(NoMethodError)
179
183
  end
180
184
  end
181
185
 
182
186
  describe "<=> comparison issue that at one time was causing segfaults on MRI" do
183
187
  it "doesn't cause the ruby process to bomb!" do
184
- Color::RED.should < Color::GREEN
185
- Color::RED.should_not > Color::GREEN
186
- Color::RED.should < Color::BLUE
188
+ expect(Color::RED).to be < Color::GREEN
189
+ expect(Color::RED).not_to be > Color::GREEN
190
+ expect(Color::RED).to be < Color::BLUE
187
191
  end
188
192
  end
189
193
 
@@ -238,44 +242,44 @@ enum :Foo2 do
238
242
  end
239
243
 
240
244
  describe "use field method to specify methods and defaults" do
241
- it "should define methods with defaults for fields" do
242
- Foo1::Baz.foo.should == "my foo"
243
- Foo2::Baz.foo.should == "my foo"
244
- Foo1::Baz.bar.should == "my bar"
245
- Foo2::Baz.bar.should == "my bar"
246
- Foo1::Baz.baz.should == Foo1::Baz.__id__
247
- Foo2::Baz.baz.should == Foo2::Baz.__id__
245
+ it "defines methods with defaults for fields" do
246
+ expect(Foo1::Baz.foo).to eq "my foo"
247
+ expect(Foo2::Baz.foo).to eq "my foo"
248
+ expect(Foo1::Baz.bar).to eq "my bar"
249
+ expect(Foo2::Baz.bar).to eq "my bar"
250
+ expect(Foo1::Baz.baz).to eq Foo1::Baz.__id__
251
+ expect(Foo2::Baz.baz).to eq Foo2::Baz.__id__
248
252
  end
249
253
  end
250
254
 
251
255
  describe "serialize and deserialize via Marshal" do
252
- it "should define methods with defaults for fields" do
253
- Marshal.load(Marshal.dump(Status::NOT_STARTED)).should == Status::NOT_STARTED
256
+ it "defines methods with defaults for fields" do
257
+ expect(Marshal.load(Marshal.dump(Status::NOT_STARTED))).to eq Status::NOT_STARTED
254
258
  end
255
259
  end
256
260
 
257
261
  if defined?(::JSON)
258
262
  describe "serialize and deserialize via JSON" do
259
- it "should define methods with defaults for fields" do
260
- JSON(JSON(Status::NOT_STARTED)).should == Status::NOT_STARTED
263
+ it "defines methods with defaults for fields" do
264
+ expect(JSON(JSON(Status::NOT_STARTED))).to eq Status::NOT_STARTED
261
265
  end
262
266
 
263
- it "should not serialize fields by default" do
267
+ it "does not serialize fields by default" do
264
268
  foo1_json = JSON(Foo1::Baz)
265
269
  foo1_hash = JSON.parse(foo1_json, :create_additions => false)
266
- foo1_hash.keys.sort.should == %w[name json_class].sort
270
+ expect(foo1_hash.keys.sort).to eq %w[name json_class].sort
267
271
  end
268
272
 
269
- it "should serialize all fields if desired" do
273
+ it "serializes all fields if desired" do
270
274
  foo1_json = Foo1::Baz.to_json(:fields => true)
271
275
  foo1_hash = JSON.parse(foo1_json, :create_additions => false)
272
- foo1_hash.keys.sort.should == %w[name json_class bar baz foo].sort
276
+ expect(foo1_hash.keys.sort).to eq %w[name json_class bar baz foo].sort
273
277
  end
274
278
 
275
- it "should serialize requested fields" do
279
+ it "serializes requested fields" do
276
280
  foo1_json = Foo1::Baz.to_json(:fields => [ :bar, 'baz' ])
277
281
  foo1_hash = JSON.parse(foo1_json, :create_additions => false)
278
- foo1_hash.keys.sort.should == %w[name json_class bar baz].sort
282
+ expect(foo1_hash.keys.sort).to eq %w[name json_class bar baz].sort
279
283
  end
280
284
  end
281
285
  end
@@ -312,5 +316,4 @@ describe "definition extensions included as models and block to use inside of th
312
316
  expect(Foo3::Baz.set_per_extension).to eq 'b_set_via_extension'
313
317
  expect(Foo3::Bang.set_per_extension).to eq 'c_set_via_extension'
314
318
  end
315
-
316
319
  end
data/test/has_set_test.rb CHANGED
@@ -169,4 +169,29 @@ class HasSetTest < Test::Unit::TestCase
169
169
  assert_equal [], party.drinks
170
170
  assert_equal 0, party.drinks_set
171
171
  end
172
+
173
+ def test_should_allow_very_large_datasets_using_string_as_column
174
+ instance = ClassWithLargeDataset.new :dataset => Dataset.all
175
+ assert_equal true, instance.save
176
+ instance.reload
177
+ assert_equal Dataset.all, instance.dataset
178
+ assert instance.dataset_set_member1
179
+ instance.dataset_set_member0 = false
180
+ instance.dataset_set_member64 = false
181
+ assert instance.save
182
+ instance.reload
183
+ assert_equal false, instance.dataset_set_member0
184
+ assert_equal false, instance.dataset_set_member64
185
+
186
+ instance.dataset = 'SetMember3, SetMember7, SetMember12'
187
+ instance.save
188
+ instance.reload
189
+ assert_equal [Dataset::SetMember3, Dataset::SetMember7, Dataset::SetMember12], instance.dataset
190
+ end
191
+
192
+ def test_read_set_attribute_works_with_two_enums
193
+ instance = TwoEnumsClass.new :drinks => Drinks.all, :dataset => Dataset.first
194
+ assert_equal Drinks.all, instance.drinks
195
+ assert_equal [Dataset.first], instance.dataset
196
+ end
172
197
  end
data/test/test_helper.rb CHANGED
@@ -53,6 +53,15 @@ def setup_db
53
53
  t.string :location
54
54
  t.integer :music_bitfield
55
55
  end
56
+
57
+ create_table :class_with_large_datasets do |t|
58
+ t.string :dataset_bitfield
59
+ end
60
+
61
+ create_table :two_enums_classes do |t|
62
+ t.integer :drinks_bitfield, :default => 0
63
+ t.string :dataset_bitfield, :default => '0'
64
+ end
56
65
  end
57
66
  end
58
67
 
@@ -105,6 +114,12 @@ enum :Drinks do
105
114
  end
106
115
  end
107
116
 
117
+ enum :Dataset do
118
+ 65.times do |i|
119
+ __send__("SetMember#{i}", {})
120
+ end
121
+ end
122
+
108
123
 
109
124
  setup_db # Init the database for class creation
110
125
 
@@ -142,4 +157,13 @@ class ClassWithIntergerColumn < ActiveRecord::Base
142
157
  has_enum :product
143
158
  end
144
159
 
160
+ class ClassWithLargeDataset < ActiveRecord::Base
161
+ has_set :dataset
162
+ end
163
+
164
+ class TwoEnumsClass < ActiveRecord::Base
165
+ has_set :drinks
166
+ has_set :dataset
167
+ end
168
+
145
169
  teardown_db # And drop them right afterwards
metadata CHANGED
@@ -1,103 +1,103 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: degu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-11 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.8
19
+ version: 1.0.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.8
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: mocha
28
+ name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: sqlite3
42
+ name: mocha
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: utils
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3.0'
90
- - - <
90
+ - - "<"
91
91
  - !ruby/object:Gem::Version
92
92
  version: '5.0'
93
93
  type: :runtime
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - '>='
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: '3.0'
100
- - - <
100
+ - - "<"
101
101
  - !ruby/object:Gem::Version
102
102
  version: '5.0'
103
103
  description: Library that includes enums, and rails support for enums and bitfield
@@ -117,8 +117,8 @@ extra_rdoc_files:
117
117
  - lib/degu/rude.rb
118
118
  - lib/degu/version.rb
119
119
  files:
120
- - .gitignore
121
- - .travis.yml
120
+ - ".gitignore"
121
+ - ".travis.yml"
122
122
  - COPYING
123
123
  - Gemfile
124
124
  - README.md
@@ -145,25 +145,25 @@ licenses: []
145
145
  metadata: {}
146
146
  post_install_message:
147
147
  rdoc_options:
148
- - --title
148
+ - "--title"
149
149
  - Degu - Library for enums and bitfield sets.
150
- - --main
150
+ - "--main"
151
151
  - README.md
152
152
  require_paths:
153
153
  - lib
154
154
  required_ruby_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - '>='
156
+ - - ">="
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  requirements:
161
- - - '>='
161
+ - - ">="
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  requirements: []
165
165
  rubyforge_project:
166
- rubygems_version: 2.0.4
166
+ rubygems_version: 2.2.1
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: Library for enums and bitfield sets.