cheddargetter_client_rails 0.1.8 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/cheddargetter_client_rails.gemspec +9 -2
- data/lib/cheddargetter_client_rails.rb +19 -7
- data/lib/generators/cheddargetter/USAGE +11 -0
- data/lib/generators/cheddargetter/cheddargetter_generator.rb +11 -0
- data/lib/generators/cheddargetter/templates/cheddargetter.yml +12 -0
- data/lib/generators/cheddargetter/templates/cheddargetter_client.rb +6 -0
- data/lib/rails/record_identifier.rb +7 -0
- data/spec/cheddargetter_client_rails_spec.rb +47 -20
- data/spec/generator_spec.rb +6 -0
- data/spec/record_identifier_spec.rb +51 -0
- metadata +11 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.14
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cheddargetter_client_rails}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.14"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brent Wooden"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-15}
|
13
13
|
s.description = %q{Integrates CheddarGetter api with Active Record. Uses cheddargetter_client_ruby.}
|
14
14
|
s.email = %q{brent.wooden@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,9 +31,16 @@ Gem::Specification.new do |s|
|
|
31
31
|
"features/support/env.rb",
|
32
32
|
"lib/cheddargetter_client_rails.rb",
|
33
33
|
"lib/cheddargetter_client_rails/subscription.rb",
|
34
|
+
"lib/generators/cheddargetter/USAGE",
|
35
|
+
"lib/generators/cheddargetter/cheddargetter_generator.rb",
|
36
|
+
"lib/generators/cheddargetter/templates/cheddargetter.yml",
|
37
|
+
"lib/generators/cheddargetter/templates/cheddargetter_client.rb",
|
38
|
+
"lib/rails/record_identifier.rb",
|
34
39
|
"spec/cheddargetter_client_rails/subscription_spec.rb",
|
35
40
|
"spec/cheddargetter_client_rails_spec.rb",
|
36
41
|
"spec/fixtures/users.yml",
|
42
|
+
"spec/generator_spec.rb",
|
43
|
+
"spec/record_identifier_spec.rb",
|
37
44
|
"spec/spec_helper.rb"
|
38
45
|
]
|
39
46
|
s.homepage = %q{http://github.com/BrentW/cheddargetter_client_rails}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'action_controller/record_identifier'
|
2
3
|
require 'cheddargetter_client_ruby'
|
4
|
+
require 'rails/record_identifier'
|
3
5
|
|
4
6
|
module CheddargetterClientRails
|
5
7
|
autoload :Subscription, 'cheddargetter_client_rails/subscription'
|
@@ -48,7 +50,10 @@ module CheddargetterClientRails
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def customer_code_column_value
|
51
|
-
|
53
|
+
if self.class.send(:customer_code_column)
|
54
|
+
value = send(self.class.send(:customer_code_column))
|
55
|
+
value.to_s if value.try(:to_s).present?
|
56
|
+
end
|
52
57
|
end
|
53
58
|
|
54
59
|
def build_subscription(attributes_hash)
|
@@ -76,15 +81,22 @@ module CheddargetterClientRails
|
|
76
81
|
end
|
77
82
|
|
78
83
|
module ClassMethods
|
79
|
-
def
|
80
|
-
|
81
|
-
self.customer_code_column = args.shift
|
84
|
+
def has_subscription(args = {})
|
85
|
+
self.customer_code_column = args.delete(:customerCode) || :id
|
82
86
|
raise ArgumentError.new("Record does not respond to #{customer_code_column.to_s}.") if !responds_to_customer_code_column?
|
83
87
|
|
84
|
-
|
85
|
-
|
88
|
+
shared = {}
|
89
|
+
shared[:email] = args.delete(:email) || :email
|
90
|
+
shared[:firstName] = args.delete(:firstName) || :first_name
|
91
|
+
shared[:lastName] = args.delete(:lastName) || :last_name
|
92
|
+
shared[:planCode] = args.delete(:planCode) || :plan_code
|
93
|
+
|
94
|
+
args.each do |key, value|
|
95
|
+
shared[key] = value
|
86
96
|
end
|
87
97
|
|
98
|
+
self.shared_columns = shared
|
99
|
+
|
88
100
|
attr_accessor :skip_cheddargetter
|
89
101
|
|
90
102
|
validate :validate_subscription
|
@@ -117,4 +129,4 @@ end
|
|
117
129
|
|
118
130
|
class ActiveRecord::Base
|
119
131
|
include CheddargetterClientRails
|
120
|
-
end
|
132
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Description:
|
2
|
+
The cheddargetter generator creates YAML file in your config
|
3
|
+
directory and an initializer to load this config. The config has a
|
4
|
+
separate section for each environment. Please fill in the YAML with
|
5
|
+
your CheddarGetter account credentials.
|
6
|
+
|
7
|
+
Examples:
|
8
|
+
rails generate cheddargetter
|
9
|
+
|
10
|
+
Config: config/cheddargetter.yml
|
11
|
+
Initializer: config/initializers/cheddargetter_client.rb
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CheddargetterGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def generate_initializer
|
5
|
+
copy_file "cheddargetter_client.rb", "config/initializers/cheddargetter_client.rb"
|
6
|
+
end
|
7
|
+
|
8
|
+
def generate_config
|
9
|
+
copy_file "cheddargetter.yml", "config/cheddargetter.yml"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
development: &development
|
2
|
+
username: youremail@example.com
|
3
|
+
password: youraccountpassword
|
4
|
+
product_code: YOUR_DEVELOPMENT_PRODUCT_CODE
|
5
|
+
|
6
|
+
test:
|
7
|
+
<<: *development
|
8
|
+
product_code: YOUR_TEST_PRODUCT_CODE
|
9
|
+
|
10
|
+
production:
|
11
|
+
<<: *development
|
12
|
+
product_code: YOUR_PRODUCTION_PRODUCT_CODE
|
@@ -0,0 +1,6 @@
|
|
1
|
+
cheddargetter_config = YAML.load_file(File.join(Rails.root, 'config', 'cheddargetter.yml'))[Rails.env]
|
2
|
+
CGClient = CheddarGetter::Client.new(
|
3
|
+
:product_code => cheddargetter_config['product_code'],
|
4
|
+
:username => cheddargetter_config['username'],
|
5
|
+
:password => cheddargetter_config['password']
|
6
|
+
)
|
@@ -0,0 +1,7 @@
|
|
1
|
+
module ActionController::RecordIdentifier
|
2
|
+
def dom_class(record_or_class, prefix = nil)
|
3
|
+
singular = ActiveModel::Naming.singular(record_or_class)
|
4
|
+
value = prefix ? "#{prefix}#{JOIN}#{singular}" : singular
|
5
|
+
value == "cheddargetter_client_rails_subscription" ? "subscription" : value
|
6
|
+
end
|
7
|
+
end
|
@@ -5,25 +5,23 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
5
5
|
describe "CheddargetterClientRails" do
|
6
6
|
before {
|
7
7
|
class TestUser < ActiveRecord::Base
|
8
|
-
attr_accessor :customer_code, :first_name, :last_name, :plan_code
|
8
|
+
attr_accessor :customer_code, :first_name, :last_name, :plan_code, :email
|
9
9
|
|
10
10
|
def self.column_names
|
11
11
|
[]
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
has_subscription :customerCode => :customer_code,
|
15
|
+
:firstName => :first_name,
|
16
|
+
:lastName => :last_name,
|
17
|
+
:ccFirstName => :first_name,
|
18
|
+
:ccLastName => :last_name,
|
19
|
+
:planCode => :plan_code
|
20
|
+
|
23
21
|
end
|
24
22
|
}
|
25
23
|
|
26
|
-
before {
|
24
|
+
before { ActiveRecord::Base.stub(:connection).and_return mock(:columns => []) }
|
27
25
|
|
28
26
|
let(:user_class) {
|
29
27
|
TestUser
|
@@ -39,18 +37,20 @@ describe "CheddargetterClientRails" do
|
|
39
37
|
end
|
40
38
|
|
41
39
|
describe "inclusion of class methods" do
|
42
|
-
subject { user_class.respond_to?(:
|
40
|
+
subject { user_class.respond_to?(:has_subscription) }
|
43
41
|
|
44
42
|
it { should be_true }
|
45
43
|
end
|
46
44
|
|
47
|
-
describe '
|
45
|
+
describe 'has_subscription' do
|
48
46
|
context 'argument errors' do
|
49
47
|
context 'without customer code column' do
|
50
48
|
subject {
|
51
49
|
class NoCustomerCodeUser < ActiveRecord::Base
|
52
|
-
|
50
|
+
has_subscription
|
53
51
|
end
|
52
|
+
NoCustomerCodeUser.stub(:connection).and_return mock(:columns => [])
|
53
|
+
|
54
54
|
}
|
55
55
|
|
56
56
|
specify { lambda { subject }.should raise_error(ArgumentError) }
|
@@ -59,13 +59,34 @@ describe "CheddargetterClientRails" do
|
|
59
59
|
context 'when record does not responsd to customer_code_column' do
|
60
60
|
subject {
|
61
61
|
class NoCustomerCodeUser < ActiveRecord::Base
|
62
|
-
|
62
|
+
has_subscription :id
|
63
63
|
end
|
64
64
|
}
|
65
65
|
specify { lambda { subject }.should raise_error }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
context 'setting default values' do
|
70
|
+
subject {
|
71
|
+
class DefaultValuesUser < ActiveRecord::Base
|
72
|
+
attr_accessor :id, :email, :first_name, :last_name, :plan_code
|
73
|
+
|
74
|
+
has_subscription
|
75
|
+
end
|
76
|
+
}
|
77
|
+
|
78
|
+
specify { lambda { subject }.should_not raise_error }
|
79
|
+
specify {
|
80
|
+
subject;
|
81
|
+
DefaultValuesUser.shared_columns.should eq({
|
82
|
+
:email => :email,
|
83
|
+
:firstName => :first_name,
|
84
|
+
:lastName => :last_name,
|
85
|
+
:planCode => :plan_code
|
86
|
+
})
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
69
90
|
context 'setting customer_code_column' do
|
70
91
|
subject { user_class.customer_code_column }
|
71
92
|
it { should eq(:customer_code) }
|
@@ -77,7 +98,8 @@ describe "CheddargetterClientRails" do
|
|
77
98
|
:lastName => :last_name,
|
78
99
|
:ccFirstName => :first_name,
|
79
100
|
:ccLastName => :last_name,
|
80
|
-
:planCode => :plan_code
|
101
|
+
:planCode => :plan_code,
|
102
|
+
:email => :email
|
81
103
|
)
|
82
104
|
}
|
83
105
|
end
|
@@ -214,7 +236,7 @@ describe "CheddargetterClientRails" do
|
|
214
236
|
['customer_code']
|
215
237
|
end
|
216
238
|
|
217
|
-
|
239
|
+
has_subscription :customerCode => :customer_code
|
218
240
|
end
|
219
241
|
}
|
220
242
|
|
@@ -240,9 +262,9 @@ describe "CheddargetterClientRails" do
|
|
240
262
|
'TEST_CODE'
|
241
263
|
end
|
242
264
|
|
243
|
-
p 'Make not that if method and not column, then it must be declared before
|
265
|
+
p 'Make not that if method and not column, then it must be declared before has_subscription'
|
244
266
|
|
245
|
-
|
267
|
+
has_subscription :customerCode => :customer_code
|
246
268
|
end
|
247
269
|
}
|
248
270
|
|
@@ -263,7 +285,7 @@ describe "CheddargetterClientRails" do
|
|
263
285
|
[]
|
264
286
|
end
|
265
287
|
|
266
|
-
|
288
|
+
has_subscription :customer_code
|
267
289
|
end
|
268
290
|
}
|
269
291
|
|
@@ -436,6 +458,11 @@ describe "CheddargetterClientRails" do
|
|
436
458
|
it { should eq('Customer Code') }
|
437
459
|
end
|
438
460
|
|
461
|
+
context 'when the customer_code_column is set and it is an integeter' do
|
462
|
+
before { user.customer_code = 12345 }
|
463
|
+
it { should eq('12345') }
|
464
|
+
end
|
465
|
+
|
439
466
|
context 'when customer_code_column is not set' do
|
440
467
|
before { user.class.stub(:customer_code_column).and_return nil }
|
441
468
|
it { should be_nil }
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "RecordIdentifier" do
|
4
|
+
before {
|
5
|
+
class TestUser < ActiveRecord::Base
|
6
|
+
attr_accessor :customer_code, :first_name, :last_name, :plan_code, :email
|
7
|
+
|
8
|
+
def self.column_names
|
9
|
+
[]
|
10
|
+
end
|
11
|
+
|
12
|
+
has_subscription :customerCode => :customer_code,
|
13
|
+
:firstName => :first_name,
|
14
|
+
:lastName => :last_name,
|
15
|
+
:ccFirstName => :first_name,
|
16
|
+
:ccLastName => :last_name,
|
17
|
+
:planCode => :plan_code
|
18
|
+
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
before { ActiveRecord::Base.stub(:connection).and_return mock(:columns => []) }
|
23
|
+
|
24
|
+
describe 'dom_class(record)' do
|
25
|
+
subject { ActionController::RecordIdentifier.dom_class(value) }
|
26
|
+
|
27
|
+
context 'called with class' do
|
28
|
+
context 'called with a CheddargetterClientRails::Subscription class' do
|
29
|
+
let(:value) { CheddargetterClientRails::Subscription }
|
30
|
+
it { should eq("subscription") }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'called with other classes' do
|
34
|
+
let(:value) { TestUser }
|
35
|
+
it { should eq("test_user") }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'called with object' do
|
40
|
+
context 'called with a CheddargetterClientRails::Subscription class' do
|
41
|
+
let(:value) { CheddargetterClientRails::Subscription.new }
|
42
|
+
it { should eq("subscription") }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'called with other classes' do
|
46
|
+
let(:value) { TestUser.new }
|
47
|
+
it { should eq("test_user") }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheddargetter_client_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 14
|
10
|
+
version: 0.1.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brent Wooden
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-15 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -134,9 +134,16 @@ files:
|
|
134
134
|
- features/support/env.rb
|
135
135
|
- lib/cheddargetter_client_rails.rb
|
136
136
|
- lib/cheddargetter_client_rails/subscription.rb
|
137
|
+
- lib/generators/cheddargetter/USAGE
|
138
|
+
- lib/generators/cheddargetter/cheddargetter_generator.rb
|
139
|
+
- lib/generators/cheddargetter/templates/cheddargetter.yml
|
140
|
+
- lib/generators/cheddargetter/templates/cheddargetter_client.rb
|
141
|
+
- lib/rails/record_identifier.rb
|
137
142
|
- spec/cheddargetter_client_rails/subscription_spec.rb
|
138
143
|
- spec/cheddargetter_client_rails_spec.rb
|
139
144
|
- spec/fixtures/users.yml
|
145
|
+
- spec/generator_spec.rb
|
146
|
+
- spec/record_identifier_spec.rb
|
140
147
|
- spec/spec_helper.rb
|
141
148
|
has_rdoc: true
|
142
149
|
homepage: http://github.com/BrentW/cheddargetter_client_rails
|