has_dynamic_columns 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ module HasDynamicColumns
2
+ module Model
3
+ module InstanceMethods
4
+ end
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module HasDynamicColumns
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -38,6 +38,82 @@ describe HasDynamicColumns do
38
38
  account
39
39
  end
40
40
 
41
+
42
+ describe HasDynamicColumns::ActiveRecord, :focus => true do
43
+ it 'should find everyone in the current account scope' do
44
+ customer = Customer.create(:account => account)
45
+ customer.fields = {
46
+ "first_name" => "Butch",
47
+ "last_name" => "Marshall",
48
+ "email" => "butch.a.marshall@gmail.com",
49
+ "trusted" => true,
50
+ }
51
+ customer.save
52
+
53
+ customer = Customer.create(:account => account)
54
+ customer.fields = {
55
+ "first_name" => "John",
56
+ "last_name" => "Paterson",
57
+ "email" => "john.paterson@gmail.com",
58
+ "trusted" => true,
59
+ }
60
+ customer.save
61
+
62
+ customer = Customer.create(:account => account)
63
+ customer.fields = {
64
+ "first_name" => "Steve",
65
+ "last_name" => "Paterson",
66
+ "email" => "steve.paterson@gmail.com",
67
+ "trusted" => true,
68
+ }
69
+ customer.save
70
+
71
+ customer = Customer.create(:account => account)
72
+ customer.fields = {
73
+ "first_name" => "Carl",
74
+ "last_name" => "Marx",
75
+ "email" => "carl@communist.com",
76
+ "trusted" => false,
77
+ }
78
+ customer.save
79
+
80
+ table = Customer.arel_table
81
+
82
+ # 1 communist
83
+ result = Customer.where.has_dynamic_columns(table[:email].matches("%gmail.com")).with_scope(account)
84
+ expect(result.length).to eq(3)
85
+
86
+ # 2 patersons
87
+ result = Customer.where.has_dynamic_columns(table[:last_name].eq("Paterson")).with_scope(account)
88
+ expect(result.length).to eq(2)
89
+
90
+ # 1 john paterson
91
+ result = Customer
92
+ .where.has_dynamic_columns(table[:first_name].eq("John")).with_scope(account)
93
+ .where.has_dynamic_columns(table[:last_name].eq("Paterson")).with_scope(account)
94
+ expect(result.length).to eq(1)
95
+ end
96
+
97
+ it 'should find the single person in this scope' do
98
+ customer = Customer.create(:account => account)
99
+ customer.fields = {
100
+ "first_name" => "Merridyth",
101
+ "last_name" => "Marshall",
102
+ "email" => "merridyth.marshall@gmail.com",
103
+ "trusted" => true,
104
+ }
105
+ customer.save
106
+
107
+ result = Customer.where.has_dynamic_columns(Customer.arel_table[:email].matches("%gmail.com")).with_scope(account)
108
+ expect(result.length).to eq(1)
109
+ end
110
+
111
+ it 'should find all 4 gmail users when no scope passed' do
112
+ result = Customer.where.has_dynamic_columns(Customer.arel_table[:email].matches("%gmail.com")).without_scope
113
+ expect(result.length).to eq(4)
114
+ end
115
+ end
116
+
41
117
  describe Product do
42
118
  subject(:product) {
43
119
  Product.new(:name => "Product #1", :account => account)
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,10 @@
1
1
  require 'logger'
2
2
  require 'rspec'
3
3
 
4
- require 'active_support/dependencies'
5
- require 'active_record'
6
-
7
4
  require 'has_dynamic_columns'
8
5
 
9
6
  if ENV['DEBUG_LOGS']
10
-
7
+
11
8
  else
12
9
 
13
10
  end
@@ -73,12 +70,12 @@ end
73
70
  class Customer < ActiveRecord::Base
74
71
  belongs_to :account
75
72
  has_many :customer_addresses
76
- has_dynamic_columns field_scope: "account", dynamic_type: "Customer", as: "fields"
73
+ has_dynamic_columns field_scope: "account", as: "fields"
77
74
  end
78
75
 
79
76
  class CustomerAddress < ActiveRecord::Base
80
77
  belongs_to :customer
81
- has_dynamic_columns field_scope: "customer.account", dynamic_type: "CustomerAddress", as: "fields"
78
+ has_dynamic_columns field_scope: "customer.account", as: "fields"
82
79
  end
83
80
 
84
81
  class Product < ActiveRecord::Base
@@ -87,10 +84,10 @@ class Product < ActiveRecord::Base
87
84
  has_many :categories, :through => :category_owners
88
85
 
89
86
  # Fields defined via the account
90
- has_dynamic_columns field_scope: "account", dynamic_type: "Product", as: "product_fields"
87
+ has_dynamic_columns field_scope: "account", as: "product_fields"
91
88
 
92
89
  # Fields defined via any associated categories
93
- has_dynamic_columns field_scope: "categories", dynamic_type: "Product", as: "category_fields"
90
+ has_dynamic_columns field_scope: "categories", as: "category_fields"
94
91
  end
95
92
 
96
93
  class Category < ActiveRecord::Base
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_dynamic_columns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Butch Marshall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-06 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '3.0'
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: '5.0'
19
+ version: '4.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '3.0'
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '5.0'
26
+ version: '4.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -61,7 +55,9 @@ dependencies:
61
55
  description: Adds ability to put dynamic fields into active record models
62
56
  email:
63
57
  - butch.a.marshall@gmail.com
64
- executables: []
58
+ executables:
59
+ - console
60
+ - setup
65
61
  extensions: []
66
62
  extra_rdoc_files: []
67
63
  files:
@@ -71,17 +67,26 @@ files:
71
67
  - LICENSE.txt
72
68
  - README.md
73
69
  - Rakefile
70
+ - bin/console
71
+ - bin/setup
74
72
  - has_dynamic_columns.gemspec
75
73
  - lib/generators/has_dynamic_columns/active_record_generator.rb
76
74
  - lib/generators/has_dynamic_columns/has_dynamic_columns_generator.rb
77
75
  - lib/generators/has_dynamic_columns/next_migration_version.rb
78
76
  - lib/generators/has_dynamic_columns/templates/migration.rb
79
77
  - lib/has_dynamic_columns.rb
78
+ - lib/has_dynamic_columns/active_record.rb
79
+ - lib/has_dynamic_columns/active_record/query_methods.rb
80
+ - lib/has_dynamic_columns/active_record/relation.rb
81
+ - lib/has_dynamic_columns/active_record_relation.rb
80
82
  - lib/has_dynamic_columns/compatibility.rb
81
83
  - lib/has_dynamic_columns/dynamic_column.rb
82
84
  - lib/has_dynamic_columns/dynamic_column_datum.rb
83
85
  - lib/has_dynamic_columns/dynamic_column_option.rb
84
86
  - lib/has_dynamic_columns/dynamic_column_validation.rb
87
+ - lib/has_dynamic_columns/model.rb
88
+ - lib/has_dynamic_columns/model/class_methods.rb
89
+ - lib/has_dynamic_columns/model/instance_methods.rb
85
90
  - lib/has_dynamic_columns/version.rb
86
91
  - spec/has_dynamic_columns_spec.rb
87
92
  - spec/spec_helper.rb