bitmask_attributes 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 56a66728b3d7243fdee612e23879a0a3f402c3bc
4
+ data.tar.gz: dd949e03d9c0e71b321f2e2cf5b8fdf5d472a1fb
5
+ SHA512:
6
+ metadata.gz: 44fd33dc8d30c3ae97f3d214fb3aa54262fbda5e1b614b6a80507c89ad43a1aa01797f89b4d5cb9511651be416f95c7085666868f7e0ad5daf1e16fdec1aa4d9
7
+ data.tar.gz: 32a51091ce2349650e90f9b24c888319b19928bb08880d245f3fdac74daa33181a6058a86cab9a58d55ad9050a1e7a9dce4d2387980ecf0d28990f48e7326211
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ Gemfile.lock
2
+ gemfiles/*.lock
1
3
  *.sw?
2
4
  .DS_Store
3
5
  coverage
@@ -7,4 +9,4 @@ pkg
7
9
  .#*
8
10
  *.gem
9
11
  /nbproject
10
- .idea/
12
+ .idea/
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use 1.9.3@bitmask_attributes --create --install
1
+ rvm 2.0.0
@@ -2,3 +2,17 @@ script: 'bundle exec rake test'
2
2
  language: ruby
3
3
  rvm:
4
4
  - 1.9.3
5
+ - 2.0.0
6
+
7
+ gemfile:
8
+ - gemfiles/3.0.gemfile
9
+ - gemfiles/3.1.gemfile
10
+ - gemfiles/3.2.gemfile
11
+ - gemfiles/4.0.gemfile
12
+
13
+ matrix:
14
+ exclude:
15
+ - rvm: 2.0.0
16
+ gemfile: gemfiles/3.0.gemfile
17
+ - rvm: 2.0.0
18
+ gemfile: gemfiles/3.1.gemfile
@@ -0,0 +1,12 @@
1
+ appraise "3.1" do
2
+ gem "rails", "~> 3.1.0"
3
+ end
4
+
5
+ appraise "3.2" do
6
+ gem "rails", "~> 3.2.0"
7
+ end
8
+
9
+ appraise "4.0" do
10
+ gem "rails", "~> 4.0.0"
11
+ gem "sass-rails", "~> 4.0.0"
12
+ end
@@ -1,4 +1,9 @@
1
- === Version 0.4.0 - 2012-12-14 19:37:49 +0000
1
+ === Version 1.0.0 - 2013-11-04
2
+
3
+ Fixes and Ruby2/Rails4 compatibility
4
+
5
+
6
+ === Version 0.4.0 - 2012-12-14
2
7
 
3
8
  Adrian Gomez (1):
4
9
  * Fixing issue #22
@@ -15,33 +20,13 @@ Dominik Bamberger (5):
15
20
 
16
21
  François DELFORT (2):
17
22
  * Handle single table inheritance
18
- * Fix for handling STI table
19
-
20
- Joel Moss (7):
21
- * Merge pull request #17 from teeparham/patch-1
22
- * Merge pull request #18 from tight/master
23
- * Merge pull request #29 from adimitrov/include-table-name
24
- * Merge pull request #33 from teeparham/or_is_null
25
- * Merge pull request #30 from pathable/default
26
- * Bundle update
27
- * Merge branch 'master' of github.com:joelmoss/bitmask_attributes
28
-
29
- Steve Hoeksema (2):
30
- * Strip trailing whitespace
31
- * Add table name to one scope that missed out
32
23
 
33
24
  Tee Parham (2):
34
- * update sample controller code
35
25
  * add table name scope to or_is_null_condition
36
26
 
37
27
  alexanderd (1):
38
28
  * Include table name in scope definitions
39
29
 
40
- steve emmons (3):
41
- * Merge pull request #26 from b4mboo/inverse_convenience
42
- * Merge pull request #25 from b4mboo/raw_bitmask_setter
43
- * Merge pull request #23 from Moove-it/master
44
-
45
30
 
46
31
  === Version 0.3.0 - 2012-04-30 21:36:18 +0100
47
32
 
@@ -73,7 +58,7 @@ steve emmons (3):
73
58
  * Merge pull request #15 from spemmons/master
74
59
 
75
60
 
76
- === Version 0.2.4 - 2011-11-23 09:37:50 +0000
61
+ === Version 0.2.4 - 2011-11-23
77
62
 
78
63
  Ivan Buiko (3):
79
64
  * No longer validates attribute during migrations
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
-
3
- require "bundler"
2
+ begin
3
+ require 'bundler/setup'
4
+ require 'appraisal'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
4
8
  Bundler::GemHelper.install_tasks
5
9
 
6
10
  require 'rake/testtask'
@@ -8,11 +8,12 @@ Gem::Specification.new do |gem|
8
8
  gem.email = "joel@developwithstyle.com"
9
9
  gem.homepage = "http://github.com/joelmoss/bitmask_attributes"
10
10
  gem.authors = ['Joel Moss']
11
-
11
+
12
12
  gem.files = `git ls-files`.split("\n")
13
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
14
  gem.require_paths = ['lib']
15
15
  gem.version = BitmaskAttributes::VERSION.dup
16
-
17
- gem.add_dependency 'activerecord', '~> 3.0'
18
- end
16
+
17
+ gem.add_dependency 'activerecord', '>= 3.1'
18
+ gem.add_development_dependency "appraisal", "~> 0.5.1"
19
+ end
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sdoc"
6
+ gem "rake"
7
+ gem "shoulda"
8
+ gem "sqlite3", ">=1.3.5"
9
+ gem "turn"
10
+ gem "rails", "~> 3.1.0"
11
+
12
+ gemspec :path=>"../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sdoc"
6
+ gem "rake"
7
+ gem "shoulda"
8
+ gem "sqlite3", ">=1.3.5"
9
+ gem "turn"
10
+ gem "rails", "~> 3.2.0"
11
+
12
+ gemspec :path=>"../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "sdoc"
6
+ gem "rake"
7
+ gem "shoulda"
8
+ gem "sqlite3", ">=1.3.5"
9
+ gem "turn"
10
+ gem "rails", "~> 4.0.0"
11
+ gem "sass-rails", "~> 4.0.0"
12
+
13
+ gemspec :path=>"../"
@@ -12,11 +12,16 @@ module BitmaskAttributes
12
12
 
13
13
  if default = options[:default]
14
14
  after_initialize do
15
- send("#{attribute}=", default) unless send("#{attribute}?")
15
+ send("#{attribute}=", default) unless send("#{attribute}?") || persisted?
16
16
  end
17
17
  end
18
18
 
19
- bitmask_definitions[attribute] = Definition.new(attribute, options[:as].to_a,options[:null].nil? || options[:null], options[:zero_value], &extension)
19
+ bitmask_definitions[attribute] = Definition.new(attribute,
20
+ options[:as].to_a,
21
+ options[:null].nil? || options[:null],
22
+ options[:zero_value],
23
+ &extension)
24
+
20
25
  bitmask_definitions[attribute].install_on(self)
21
26
  end
22
27
 
@@ -38,6 +43,12 @@ module BitmaskAttributes
38
43
  @bitmasks ||= {}
39
44
  end
40
45
  end
46
+
47
+ def reload(*)
48
+ super
49
+ self.class.bitmasks.keys.each{|attribute| self.send("reload_#{attribute}")}
50
+ self
51
+ end
41
52
  end
42
53
 
43
54
  ActiveRecord::Base.send :include, BitmaskAttributes
@@ -2,7 +2,7 @@ module BitmaskAttributes
2
2
  class Definition
3
3
  attr_reader :attribute, :values, :allow_null, :zero_value, :extension
4
4
 
5
- def initialize(attribute, values=[],allow_null = true,zero_value = nil, &extension)
5
+ def initialize(attribute, values=[], allow_null = true, zero_value = nil, &extension)
6
6
  @attribute = attribute
7
7
  @values = values
8
8
  @extension = extension
@@ -60,6 +60,9 @@ module BitmaskAttributes
60
60
  def #{attribute}
61
61
  @#{attribute} ||= BitmaskAttributes::ValueProxy.new(self, :#{attribute}, &self.class.bitmask_definitions[:#{attribute}].extension)
62
62
  end
63
+ def reload_#{attribute}
64
+ @#{attribute} = nil
65
+ end
63
66
  )
64
67
  end
65
68
 
@@ -1,3 +1,3 @@
1
1
  module BitmaskAttributes
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class BitmaskAttributesTest < ActiveSupport::TestCase
4
4
 
5
- def self.context_with_classes(label,campaign_class,company_class)
5
+ def self.context_with_classes(label, campaign_class, company_class)
6
6
  context label do
7
7
  setup do
8
8
  @campaign_class = campaign_class
@@ -139,6 +139,19 @@ class BitmaskAttributesTest < ActiveSupport::TestCase
139
139
  assert_stored campaign, :web, :print
140
140
  end
141
141
 
142
+ should "update bitmask values currently in the database with reload" do
143
+ instance1 = @campaign_class.create(:medium => [:web, :print])
144
+ instance2 = @campaign_class.find(instance1.id)
145
+ assert instance1.id == instance2.id
146
+ assert instance1.object_id != instance2.object_id
147
+ assert instance1.update_attributes(:medium => [:email])
148
+
149
+ assert_equal [:web, :print],instance2.medium
150
+
151
+ assert_equal @campaign_class,instance2.reload.class
152
+ assert_equal [:email],instance2.medium
153
+ end
154
+
142
155
  context "checking" do
143
156
  setup { @campaign = @campaign_class.new(:medium => [:web, :print]) }
144
157
 
@@ -240,7 +253,7 @@ class BitmaskAttributesTest < ActiveSupport::TestCase
240
253
  assert campaign.save
241
254
 
242
255
  assert_equal(
243
- @campaign_class.find(:all, :conditions => ['medium & ? <> 0', @campaign_class.bitmask_for_medium(:print)]),
256
+ @campaign_class.where('medium & ? <> 0', @campaign_class.bitmask_for_medium(:print)).to_a,
244
257
  @campaign_class.medium_for_print
245
258
  )
246
259
 
@@ -305,9 +318,33 @@ class BitmaskAttributesTest < ActiveSupport::TestCase
305
318
  assert_equal DefaultValue.new(:default_sym => :x).default_sym, [:x]
306
319
  assert_equal DefaultValue.new(:default_array => [:x]).default_array, [:x]
307
320
  end
321
+
322
+ should "save empty bitmask when default defined" do
323
+ default = DefaultValue.create
324
+ assert_equal [:y], default.default_sym
325
+ default.default_sym = []
326
+ default.save
327
+ assert_empty default.default_sym
328
+ default2 = DefaultValue.find(default.id)
329
+ assert_empty default2.default_sym
330
+ end
308
331
 
309
- context_with_classes 'Campaign with null attributes',CampaignWithNull,CompanyWithNull
310
- context_with_classes 'Campaign without null attributes',CampaignWithoutNull,CompanyWithoutNull
311
- context_with_classes 'SubCampaign with null attributes',SubCampaignWithNull,CompanyWithNull
312
- context_with_classes 'SubCampaign without null attributes',SubCampaignWithoutNull,CompanyWithoutNull
332
+ context_with_classes 'Campaign with null attributes', CampaignWithNull, CompanyWithNull
333
+ context_with_classes 'Campaign without null attributes', CampaignWithoutNull, CompanyWithoutNull
334
+ context_with_classes 'SubCampaign with null attributes', SubCampaignWithNull, CompanyWithNull
335
+ context_with_classes 'SubCampaign without null attributes', SubCampaignWithoutNull, CompanyWithoutNull
336
+
337
+ should "allow subclasses to have different values for bitmask than parent" do
338
+ a = CampaignWithNull.new
339
+ b = SubCampaignWithNull.new
340
+ a.different_per_class = [:set_for_parent]
341
+ b.different_per_class = [:set_for_sub]
342
+ a.save!
343
+ b.save!
344
+ a.reload
345
+ b.reload
346
+ assert_equal a.different_per_class, [:set_for_parent]
347
+ assert_equal b.different_per_class, [:set_for_sub]
348
+ end
349
+
313
350
  end
@@ -2,6 +2,7 @@ ActiveRecord::Schema.define do
2
2
  create_table :campaign_with_nulls do |t|
3
3
  t.integer :company_id
4
4
  t.integer :medium, :allow_zero, :misc, :Legacy
5
+ t.integer :different_per_class
5
6
  t.string :type # STI
6
7
  end
7
8
  create_table :company_with_nulls do |t|
@@ -10,6 +11,7 @@ ActiveRecord::Schema.define do
10
11
  create_table :campaign_without_nulls do |t|
11
12
  t.integer :company_id
12
13
  t.integer :medium, :allow_zero, :misc, :Legacy, :null => false, :default => 0
14
+ t.integer :different_per_class
13
15
  t.string :type # STI
14
16
  end
15
17
  create_table :company_without_nulls do |t|
@@ -30,6 +32,7 @@ class CampaignWithNull < ActiveRecord::Base
30
32
  belongs_to :company,:class_name => 'CompanyWithNull'
31
33
  bitmask :medium, :as => [:web, :print, :email, :phone]
32
34
  bitmask :allow_zero, :as => [:one, :two, :three], :zero_value => :none
35
+ bitmask :different_per_class, :as => [:set_for_parent]
33
36
  bitmask :misc, :as => %w(some useless values) do
34
37
  def worked?
35
38
  true
@@ -39,6 +42,7 @@ class CampaignWithNull < ActiveRecord::Base
39
42
  end
40
43
 
41
44
  class SubCampaignWithNull < CampaignWithNull
45
+ bitmask :different_per_class, :as => [:set_for_sub]
42
46
  end
43
47
 
44
48
  class CompanyWithoutNull < ActiveRecord::Base
@@ -3,9 +3,9 @@ require 'bundler/setup'
3
3
 
4
4
  require 'test/unit'
5
5
  begin; require 'turn'; rescue LoadError; end
6
- require 'shoulda'
7
6
 
8
7
  require 'active_record'
8
+ require 'shoulda'
9
9
 
10
10
  $:.unshift File.expand_path("../../lib", __FILE__)
11
11
  require 'bitmask_attributes'
metadata CHANGED
@@ -1,32 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitmask_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Joel Moss
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-14 00:00:00.000000000 Z
11
+ date: 2013-11-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
- version: '3.0'
19
+ version: '3.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
26
37
  requirements:
27
38
  - - ~>
28
39
  - !ruby/object:Gem::Version
29
- version: '3.0'
40
+ version: 0.5.1
30
41
  description:
31
42
  email: joel@developwithstyle.com
32
43
  executables: []
@@ -37,9 +48,9 @@ files:
37
48
  - .gitignore
38
49
  - .rvmrc
39
50
  - .travis.yml
51
+ - Appraisals
40
52
  - CHANGELOG.rdoc
41
53
  - Gemfile
42
- - Gemfile.lock
43
54
  - LICENSE
44
55
  - README.rdoc
45
56
  - Rakefile
@@ -76,6 +87,9 @@ files:
76
87
  - doc/panel/index.html
77
88
  - doc/panel/links.html
78
89
  - doc/panel/tree.js
90
+ - gemfiles/3.1.gemfile
91
+ - gemfiles/3.2.gemfile
92
+ - gemfiles/4.0.gemfile
79
93
  - lib/bitmask_attributes.rb
80
94
  - lib/bitmask_attributes/definition.rb
81
95
  - lib/bitmask_attributes/value_proxy.rb
@@ -86,27 +100,26 @@ files:
86
100
  - test/test_helper.rb
87
101
  homepage: http://github.com/joelmoss/bitmask_attributes
88
102
  licenses: []
103
+ metadata: {}
89
104
  post_install_message:
90
105
  rdoc_options: []
91
106
  require_paths:
92
107
  - lib
93
108
  required_ruby_version: !ruby/object:Gem::Requirement
94
- none: false
95
109
  requirements:
96
- - - ! '>='
110
+ - - '>='
97
111
  - !ruby/object:Gem::Version
98
112
  version: '0'
99
113
  required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
114
  requirements:
102
- - - ! '>='
115
+ - - '>='
103
116
  - !ruby/object:Gem::Version
104
117
  version: '0'
105
118
  requirements: []
106
119
  rubyforge_project:
107
- rubygems_version: 1.8.23
120
+ rubygems_version: 2.1.2
108
121
  signing_key:
109
- specification_version: 3
122
+ specification_version: 4
110
123
  summary: Simple bitmask attribute support for ActiveRecord
111
124
  test_files:
112
125
  - test/bitmask_attributes/definition_test.rb
@@ -1,59 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- bitmask_attributes (0.3.0)
5
- activerecord (~> 3.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.2.9)
11
- activesupport (= 3.2.9)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.9)
14
- activemodel (= 3.2.9)
15
- activesupport (= 3.2.9)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.9)
19
- i18n (~> 0.6)
20
- multi_json (~> 1.0)
21
- ansi (1.4.3)
22
- arel (3.0.2)
23
- bourne (1.1.2)
24
- mocha (= 0.10.5)
25
- builder (3.0.4)
26
- i18n (0.6.1)
27
- json (1.7.5)
28
- metaclass (0.0.1)
29
- mocha (0.10.5)
30
- metaclass (~> 0.0.1)
31
- multi_json (1.5.0)
32
- rake (10.0.3)
33
- rdoc (3.12)
34
- json (~> 1.4)
35
- sdoc (0.3.20)
36
- json (>= 1.1.3)
37
- rdoc (~> 3.10)
38
- shoulda (3.3.2)
39
- shoulda-context (~> 1.0.1)
40
- shoulda-matchers (~> 1.4.1)
41
- shoulda-context (1.0.1)
42
- shoulda-matchers (1.4.2)
43
- activesupport (>= 3.0.0)
44
- bourne (~> 1.1.2)
45
- sqlite3 (1.3.6)
46
- turn (0.9.6)
47
- ansi
48
- tzinfo (0.3.35)
49
-
50
- PLATFORMS
51
- ruby
52
-
53
- DEPENDENCIES
54
- bitmask_attributes!
55
- rake
56
- sdoc
57
- shoulda
58
- sqlite3 (>= 1.3.5)
59
- turn