bitmasker 0.3.1 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8e18e40165c1a709f4d8c17576fd36584f53bf5
4
- data.tar.gz: 2d93c535a39aaa6d580d2fb99568e54ac92948bf
3
+ metadata.gz: e791e75331fc95bfeaa6a78b546d9ebefa5060d3
4
+ data.tar.gz: 1936a77afe674e2fdd355a5194a1200a09be30ca
5
5
  SHA512:
6
- metadata.gz: a24fbbac996502ed2bf30641d2497e290db8da3d80a05c6e43ef7be8a1171f40b82111bc85f3a207b9fa73f5320a6b8febfd35750119d5982ae86e67344c1345
7
- data.tar.gz: 892fc1cde3deda78f16dc566d5f2aeaa1ea93f24a5b2f8b78ac4ac0645b1632758e8632e1f15ed0500310315d2c4754804a4627f03d704aaf136d0feaf2ea7e3
6
+ metadata.gz: 95ac3d11a288dbe0e743f5b0422bb07a8fd877bfeb519c16e93676cc1c8b044b11313a47d4ce6f8a851fd58ac28fa72ebe543ee4c2b7b8dc52bc809134a1e822
7
+ data.tar.gz: c6ca3c910115b6a95f40be1fe9e9e5d8954edad1bab6d9f0a1854390696fbdb79c092547a43c947a1bfabcd404bafb27a3895eabb01f53fb8d44933cabbc2b43
@@ -7,6 +7,7 @@ module Bitmasker
7
7
 
8
8
  class_attribute :model_class
9
9
  class_attribute :field_name
10
+ class_attribute :table_name
10
11
  class_attribute :mask_name
11
12
  class_attribute :bitmask_attributes
12
13
 
@@ -20,6 +21,7 @@ module Bitmasker
20
21
  end
21
22
 
22
23
  klass.model_class = model_class
24
+ klass.table_name = model_class.table_name
23
25
  klass.field_name = field_name
24
26
  klass.mask_name = mask_name
25
27
  klass.bitmask_attributes = bitmask_attributes.stringify_keys
@@ -34,17 +36,17 @@ module Bitmasker
34
36
  # REVIEW: This (the unused _ attribute) tells me I have the design wrong
35
37
  def with_attribute(_, *attributes)
36
38
  # TODO: Test lots of databases
37
- bitmask_query attributes, "#{field_name} & :mask = :mask"
39
+ bitmask_query attributes, "#{table_name}.#{field_name} & :mask = :mask"
38
40
  end
39
41
 
40
42
  def with_any_attribute(_, *attributes)
41
43
  # TODO: Test lots of databases
42
- bitmask_query attributes, "#{field_name} & :mask <> 0"
44
+ bitmask_query attributes, "#{table_name}.#{field_name} & :mask <> 0"
43
45
  end
44
46
 
45
47
  def without_attribute(_, *attributes)
46
48
  # TODO: Test lots of databases
47
- bitmask_query attributes, "#{field_name} & :mask = 0 OR #{field_name} IS NULL"
49
+ bitmask_query attributes, "#{table_name}.#{field_name} & :mask = 0 OR #{table_name}.#{field_name} IS NULL"
48
50
  end
49
51
 
50
52
  private
@@ -1,3 +1,3 @@
1
1
  module Bitmasker
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -3,6 +3,10 @@ require 'test_helper'
3
3
  class Bitmasker::BitmaskAttributesTest < MiniTest::Unit::TestCase
4
4
 
5
5
  MockModel = Class.new do
6
+ def self.table_name
7
+ "mock_models"
8
+ end
9
+
6
10
  def self.value_to_boolean(value)
7
11
  !!value
8
12
  end
@@ -2,7 +2,11 @@ require 'test_helper'
2
2
 
3
3
  class Bitmasker::BitmaskScopeTest < MiniTest::Unit::TestCase
4
4
 
5
- MockModel = Class.new
5
+ MockModel = Class.new do
6
+ def self.table_name
7
+ "mock_models"
8
+ end
9
+ end
6
10
 
7
11
  def model_instance
8
12
  @model_instance ||= MockModel.new
@@ -27,27 +31,27 @@ class Bitmasker::BitmaskScopeTest < MiniTest::Unit::TestCase
27
31
 
28
32
 
29
33
  def test_with_attribute
30
- MockModel.expects(:where).with("email_mask & :mask = :mask", mask: 1)
34
+ MockModel.expects(:where).with("mock_models.email_mask & :mask = :mask", mask: 1)
31
35
  subject.with_emails(:send_weekly_email)
32
36
  end
33
37
 
34
38
  def test_with_attributes_array
35
- MockModel.expects(:where).with("email_mask & :mask = :mask", mask: 6)
39
+ MockModel.expects(:where).with("mock_models.email_mask & :mask = :mask", mask: 6)
36
40
  subject.with_emails([:send_monthly_newsletter, :send_daily_spam])
37
41
  end
38
42
 
39
43
  def test_with_attributes
40
- MockModel.expects(:where).with("email_mask & :mask = :mask", mask: 6)
44
+ MockModel.expects(:where).with("mock_models.email_mask & :mask = :mask", mask: 6)
41
45
  subject.with_emails(:send_monthly_newsletter, :send_daily_spam)
42
46
  end
43
47
 
44
48
  def test_without_attribute
45
- MockModel.expects(:where).with("email_mask & :mask = 0 OR email_mask IS NULL", mask: 2)
49
+ MockModel.expects(:where).with("mock_models.email_mask & :mask = 0 OR mock_models.email_mask IS NULL", mask: 2)
46
50
  subject.without_emails(:send_monthly_newsletter)
47
51
  end
48
52
 
49
53
  def test_with_any_attribute
50
- MockModel.expects(:where).with("email_mask & :mask <> 0", mask: 3)
54
+ MockModel.expects(:where).with("mock_models.email_mask & :mask <> 0", mask: 3)
51
55
  subject.with_any_emails([:send_weekly_email, :send_monthly_newsletter])
52
56
  end
53
57
  end
@@ -6,6 +6,10 @@ class MockModel
6
6
  attr_accessor :another_dummy_mask
7
7
  extend Bitmasker::Model
8
8
 
9
+ def self.table_name
10
+ "mock_models"
11
+ end
12
+
9
13
  def []=(sym, value)
10
14
  send "#{ sym }=", value
11
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitmasker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amiel Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-23 00:00:00.000000000 Z
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bitmask