redline 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  ## MAC OS
2
2
  .DS_Store
3
+ Icon*
3
4
 
4
5
  ## TEXTMATE
5
6
  *.tmproj
@@ -11,7 +11,7 @@ Redline also includes a lightweight manual subscription billing system, if you d
11
11
 
12
12
  === This software is delivered "as is" without warranty. As with any piece of code, please study it if you include it in your project, especially for such a critical component of your application.
13
13
 
14
- While I believe the tests cover the code well, there may be certain cases that I have not expirienced or predicted. This is a manual billing script, so dreadful things may occur; please help out and add to the tests if you see, or god forbid expirience, any problems.
14
+ While I believe the tests cover the code well, there may be certain cases that I have not experienced or predicted. This is a manual billing script, so dreadful things may occur; please help out and add to the tests if you see, or god forbid experience, any problems.
15
15
 
16
16
  It is my intention to convert to gateway handled subscriptions, once Braintree adds this functionality to their gem.
17
17
 
@@ -56,7 +56,8 @@ If you don't like the default settings or your user needs a field mapping, you c
56
56
 
57
57
  class User < ActiveRecord::Base
58
58
  has_a_braintree_customer do
59
- attribute_map :firstname => :first_name, :lastname => :last_name
59
+ attribute_map :first_name => :firstname, :last_name => :lastname
60
+ custom_fields :ip_address, :tax_id
60
61
  end
61
62
 
62
63
  has_a_subscription do
@@ -71,10 +72,8 @@ If you don't like the default settings or your user needs a field mapping, you c
71
72
 
72
73
  * Fork the project.
73
74
  * Make your feature addition or bug fix.
74
- * Add tests for it. This is important so I don't break it in a
75
- future version unintentionally.
76
- * Commit, do not mess with rakefile, version, or history.
77
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
75
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
76
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
78
77
  * Send me a pull request. Bonus points for topic branches.
79
78
 
80
79
  == Copyright
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -11,7 +11,8 @@ module RedLine
11
11
  before_create :create_customer
12
12
  before_update :update_customer
13
13
  before_destroy :delete_customer
14
- cattr_accessor :braintree_customer
14
+ cattr_accessor :braintree_customer_attribute_map
15
+ cattr_accessor :braintree_customer_custom_fields
15
16
  end
16
17
  end
17
18
  end
@@ -3,10 +3,8 @@ module RedLine
3
3
  module InstanceMethods
4
4
  def braintree_customer_attributes
5
5
  wanted_attributes = Braintree::Customer._create_signature.reject{|a| a.is_a? Hash}.reject{|a| a == :id}
6
- attributes.symbolize_keys.inject({}) do |rewritten_hash, (original_key, value)|
7
- rewritten_hash[self.class.braintree_customer.fetch(original_key, original_key)] = value
8
- rewritten_hash
9
- end.reject{|key, value| !wanted_attributes.include?(key)}
6
+ wanted_attributes.inject({}) {|hash, key| hash.merge(key => (self.send(self.class.braintree_customer_attribute_map[key] || key) rescue nil))}.
7
+ merge(:custom_fields => self.class.braintree_customer_custom_fields.inject({}) {|hash, key| hash.merge(key => (self.send(self.class.braintree_customer_attribute_map[key] || key) rescue nil))})
10
8
  end
11
9
  def customer
12
10
  Braintree::Customer.find(customer_id) if customer_id
@@ -2,10 +2,14 @@ module RedLine
2
2
  module Customer
3
3
  module Settings
4
4
  def set_default_customer_options
5
- attribute_map {} unless (send :braintree_customer)
5
+ attribute_map unless (send :braintree_customer_attribute_map)
6
+ custom_fields unless (send :braintree_customer_custom_fields)
6
7
  end
7
8
  def attribute_map(attributes = {})
8
- self.braintree_customer = attributes
9
+ self.braintree_customer_attribute_map = attributes
10
+ end
11
+ def custom_fields(*attributes)
12
+ self.braintree_customer_custom_fields = attributes
9
13
  end
10
14
  end
11
15
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{redline}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Daniels"]
12
- s.date = %q{2010-02-10}
12
+ s.date = %q{2010-03-06}
13
13
  s.description = %q{Syncs your AR models with Braintree (Payment Gateway) and offers a lightweight reoccurring billing script}
14
14
  s.email = %q{james@marginleft.com}
15
15
  s.extra_rdoc_files = [
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
45
45
  s.homepage = %q{http://github.com/jamesdaniels/redline}
46
46
  s.rdoc_options = ["--charset=UTF-8"]
47
47
  s.require_paths = ["lib"]
48
- s.rubygems_version = %q{1.3.5}
48
+ s.rubygems_version = %q{1.3.6}
49
49
  s.summary = %q{Syncs your AR models with Braintree (Payment Gateway) and offers a lightweight reoccurring billing script}
50
50
  s.test_files = [
51
51
  "spec/billing_spec.rb",
@@ -17,7 +17,8 @@ describe User do
17
17
  end
18
18
 
19
19
  it "should have a empty braintree_customer" do
20
- User.braintree_customer.should eql({})
20
+ User.braintree_customer_attribute_map.should eql({})
21
+ User.braintree_customer_custom_fields.should eql([])
21
22
  end
22
23
 
23
24
  it "should inherit the instance methods" do
@@ -25,7 +26,7 @@ describe User do
25
26
  (User.instance_methods & expected_methods).sort.should eql(expected_methods.sort)
26
27
  end
27
28
  it "should have proper braintree attributes" do
28
- valid_user.braintree_customer_attributes.should eql({:first_name=>"James", :last_name=>"Daniels", :email=>"james@marginleft.com"})
29
+ valid_user.braintree_customer_attributes.should eql({:first_name=>"James", :last_name=>"Daniels", :email=>"james@marginleft.com", :custom_fields=>{}})
29
30
  end
30
31
  it "should fire Braintree::Customer.create!" do
31
32
  Braintree::Customer.should_receive('create!').with(valid_user.braintree_customer_attributes).and_return(mock_customer)
@@ -61,7 +62,8 @@ end
61
62
  describe ComplexUser do
62
63
 
63
64
  it "should have a empty braintree_customer" do
64
- ComplexUser.braintree_customer.should eql({:firstname=>:first_name, :lastname=>:last_name})
65
+ ComplexUser.braintree_customer_attribute_map.should eql({:first_name=>:firstname, :last_name=>:lastname})
66
+ ComplexUser.braintree_customer_custom_fields.should eql([:unused_attribute])
65
67
  end
66
68
  it "should have proper braintree attributes" do
67
69
  Braintree::Customer.stub!('_create_signature').and_return([:first_name, :last_name, :email])
@@ -70,7 +72,25 @@ describe ComplexUser do
70
72
  :lastname => 'Daniels',
71
73
  :email => 'james@marginleft.com',
72
74
  :unused_attribute => 'unused'
73
- ).braintree_customer_attributes.should eql({:first_name=>"James", :last_name=>"Daniels", :email=>"james@marginleft.com"})
75
+ ).braintree_customer_attributes.should eql({:first_name=>"James", :last_name=>"Daniels", :email=>"james@marginleft.com", :custom_fields=>{:unused_attribute=>"unused"}})
74
76
  end
75
77
 
78
+ end
79
+
80
+ describe UserWithoutTrial do
81
+
82
+ it "should have a empty braintree_customer" do
83
+ UserWithoutTrial.braintree_customer_attribute_map.should eql({:first_name=>:firstname, :something=>:firstname, :last_name=>:lastname})
84
+ UserWithoutTrial.braintree_customer_custom_fields.should eql([:something])
85
+ end
86
+ it "should have proper braintree attributes" do
87
+ Braintree::Customer.stub!('_create_signature').and_return([:first_name, :last_name, :email])
88
+ UserWithoutTrial.new(
89
+ :firstname => 'James',
90
+ :lastname => 'Daniels',
91
+ :email => 'james@marginleft.com',
92
+ :unused_attribute => 'unused'
93
+ ).braintree_customer_attributes.should eql({:first_name=>"James", :custom_fields=>{:something=>"James"}, :last_name=>"Daniels", :email=>"james@marginleft.com"})
94
+ end
95
+
76
96
  end
@@ -13,7 +13,8 @@ end
13
13
  class ComplexUser < ActiveRecord::Base
14
14
 
15
15
  has_a_braintree_customer do
16
- attribute_map :firstname => :first_name, :lastname => :last_name
16
+ attribute_map :first_name => :firstname, :last_name => :lastname
17
+ custom_fields :unused_attribute
17
18
  end
18
19
 
19
20
  has_a_subscription do
@@ -30,7 +31,8 @@ end
30
31
  class UserWithoutTrial < ActiveRecord::Base
31
32
 
32
33
  has_a_braintree_customer do
33
- attribute_map :firstname => :first_name, :lastname => :last_name
34
+ attribute_map :first_name => :firstname, :last_name => :lastname, :something => :firstname
35
+ custom_fields :something
34
36
  end
35
37
 
36
38
  has_a_subscription do
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - James Daniels
@@ -9,49 +14,59 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-10 00:00:00 -05:00
17
+ date: 2010-03-06 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
23
31
  version: 1.2.9
24
- version:
32
+ type: :development
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: braintree
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
33
43
  version: "0"
34
- version:
44
+ type: :development
45
+ version_requirements: *id002
35
46
  - !ruby/object:Gem::Dependency
36
47
  name: activerecord
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
40
50
  requirements:
41
51
  - - ">="
42
52
  - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
43
55
  version: "0"
44
- version:
56
+ type: :development
57
+ version_requirements: *id003
45
58
  - !ruby/object:Gem::Dependency
46
59
  name: activesupport
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
60
+ prerelease: false
61
+ requirement: &id004 !ruby/object:Gem::Requirement
50
62
  requirements:
51
63
  - - ">="
52
64
  - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
53
67
  version: "0"
54
- version:
68
+ type: :development
69
+ version_requirements: *id004
55
70
  description: Syncs your AR models with Braintree (Payment Gateway) and offers a lightweight reoccurring billing script
56
71
  email: james@marginleft.com
57
72
  executables: []
@@ -99,18 +114,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
114
  requirements:
100
115
  - - ">="
101
116
  - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
102
119
  version: "0"
103
- version:
104
120
  required_rubygems_version: !ruby/object:Gem::Requirement
105
121
  requirements:
106
122
  - - ">="
107
123
  - !ruby/object:Gem::Version
124
+ segments:
125
+ - 0
108
126
  version: "0"
109
- version:
110
127
  requirements: []
111
128
 
112
129
  rubyforge_project:
113
- rubygems_version: 1.3.5
130
+ rubygems_version: 1.3.6
114
131
  signing_key:
115
132
  specification_version: 3
116
133
  summary: Syncs your AR models with Braintree (Payment Gateway) and offers a lightweight reoccurring billing script