redline 0.1.1 → 0.1.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.
- data/LICENSE +1 -1
 - data/README.rdoc +30 -5
 - data/Rakefile +2 -1
 - data/VERSION +1 -1
 - data/lib/redline.rb +5 -11
 - data/redline.gemspec +12 -3
 - data/spec/db/database.yml +3 -0
 - data/spec/db/models.rb +15 -0
 - data/spec/db/schema.rb +16 -0
 - data/spec/db/test.sqlite3 +0 -0
 - data/spec/redline_spec.rb +67 -4
 - data/spec/spec_helper.rb +21 -0
 - metadata +18 -2
 
    
        data/LICENSE
    CHANGED
    
    
    
        data/README.rdoc
    CHANGED
    
    | 
         @@ -2,18 +2,43 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            Braintree via Redline: riding the rails
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
            Redline helps you with Braintree on Rails, it automatically makes creation/deletion/update scripts for your model, translating and syncing them with a Braintree customer profile. In the future I plan to increase the capabilities with helpers for Braintree models and light-weight subscription support, perhaps using Braintree's reoccurring billing.
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
            == Getting started
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
            Set up the gem dependancies in environment.rb:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              config.gem 'braintree'
         
     | 
| 
      
 12 
     | 
    
         
            +
              config.gem 'redline'
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            Run your install task:
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              $ rake gems:install
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            Configure Braintree normally in an initializer:
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              Braintree::Configuration.environment = CONFIG[:braintree][:environment].to_sym
         
     | 
| 
      
 21 
     | 
    
         
            +
              Braintree::Configuration.merchant_id = CONFIG[:braintree][:merchant_id]
         
     | 
| 
      
 22 
     | 
    
         
            +
              Braintree::Configuration.public_key  = CONFIG[:braintree][:public_key]
         
     | 
| 
      
 23 
     | 
    
         
            +
              Braintree::Configuration.private_key = CONFIG[:braintree][:private_key]
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            Add acts_as_braintree_customer and a column customer_id:integer to a model of your choice:
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              add_column :users, :customer_id, :integer
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              Class User < ActiveRecord::Base
         
     | 
| 
      
 30 
     | 
    
         
            +
                acts_as_braintree_customer
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            == Example and configuration
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            acts_as_braintree_customer takes an optional series of attributes that represent an attribute[] mapper
         
     | 
| 
       9 
36 
     | 
    
         | 
| 
       10 
37 
     | 
    
         
             
              class User < ActiveRecord::Base
         
     | 
| 
       11 
38 
     | 
    
         
             
                acts_as_braintree_customer :business_name => :company, :firstname => :first_name, :lastname => :last_name
         
     | 
| 
       12 
39 
     | 
    
         
             
                attr_accessible :firstname, :lastname, :website, :email, :business_name, :password, :password_confirmation
         
     | 
| 
       13 
40 
     | 
    
         
             
              end
         
     | 
| 
       14 
41 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
            acts_as_braintree_customer takes an optional series of attributes that represent an attribute[] mapper
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
42 
     | 
    
         
             
              james = User.find(1) #=> <User id: 1, firstname: "James", lastname: "Daniels", business_name: "MarginLeft, LLC", email: 'james@jamesdaniels.net', website: 'http://www.marginleft.com', crypted_password: "45fres8...", persistence_token: "4jsdf88...", ...>
         
     | 
| 
       18 
43 
     | 
    
         
             
              james.customer #=> <Braintree::Customer id: "9999999", first_name: "James", last_name: "Daniels", company: "MarginLeft, LLC", email: "james@jamesdaniels.net", website: "http://www.marginleft.com", ..., addresses: [], credit_cards: []>
         
     | 
| 
       19 
44 
     | 
    
         | 
| 
         @@ -31,4 +56,4 @@ More to come. 
     | 
|
| 
       31 
56 
     | 
    
         | 
| 
       32 
57 
     | 
    
         
             
            == Copyright
         
     | 
| 
       33 
58 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
            Copyright (c) 2010  
     | 
| 
      
 59 
     | 
    
         
            +
            Copyright (c) 2010 MarginLeft, LLC. See LICENSE for details.
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -7,12 +7,13 @@ begin 
     | 
|
| 
       7 
7 
     | 
    
         
             
                gem.name = "redline"
         
     | 
| 
       8 
8 
     | 
    
         
             
                gem.summary = %Q{Braintree via redline: riding the rails}
         
     | 
| 
       9 
9 
     | 
    
         
             
                gem.description = %Q{Manual subscriptions via the Braintree gem}
         
     | 
| 
       10 
     | 
    
         
            -
                gem.email = "james@ 
     | 
| 
      
 10 
     | 
    
         
            +
                gem.email = "james@marginleft.com"
         
     | 
| 
       11 
11 
     | 
    
         
             
                gem.homepage = "http://github.com/jamesdaniels/redline"
         
     | 
| 
       12 
12 
     | 
    
         
             
                gem.authors = ["James Daniels"]
         
     | 
| 
       13 
13 
     | 
    
         
             
                gem.add_development_dependency "rspec", ">= 1.2.9"
         
     | 
| 
       14 
14 
     | 
    
         
             
                gem.add_development_dependency "braintree"
         
     | 
| 
       15 
15 
     | 
    
         
             
                gem.add_development_dependency "activerecord"
         
     | 
| 
      
 16 
     | 
    
         
            +
                gem.add_development_dependency "activesupport"
         
     | 
| 
       16 
17 
     | 
    
         
             
                # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
         
     | 
| 
       17 
18 
     | 
    
         
             
              end
         
     | 
| 
       18 
19 
     | 
    
         
             
              Jeweler::GemcutterTasks.new
         
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.1. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.1.2
         
     | 
    
        data/lib/redline.rb
    CHANGED
    
    | 
         @@ -1,17 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'rubygems'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'active_record'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            class Hash
         
     | 
| 
       5 
     | 
    
         
            -
            	def rewrite mapping
         
     | 
| 
       6 
     | 
    
         
            -
            		inject({}) do |rewritten_hash, (original_key, value)|
         
     | 
| 
       7 
     | 
    
         
            -
            			rewritten_hash[mapping.fetch(original_key, original_key)] = value
         
     | 
| 
       8 
     | 
    
         
            -
            			rewritten_hash
         
     | 
| 
       9 
     | 
    
         
            -
            		end
         
     | 
| 
       10 
     | 
    
         
            -
            	end
         
     | 
| 
       11 
     | 
    
         
            -
            end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
4 
     | 
    
         
             
            module RedLine
         
     | 
| 
       14 
     | 
    
         
            -
            	def acts_as_braintree_customer(attribute_rewriting)
         
     | 
| 
      
 5 
     | 
    
         
            +
            	def acts_as_braintree_customer(attribute_rewriting = {})
         
     | 
| 
       15 
6 
     | 
    
         
             
            		send :include, RedLine::Customer
         
     | 
| 
       16 
7 
     | 
    
         
             
            		send 'braintree_customer=', attribute_rewriting
         
     | 
| 
       17 
8 
     | 
    
         
             
            	end
         
     | 
| 
         @@ -30,7 +21,10 @@ module RedLine 
     | 
|
| 
       30 
21 
     | 
    
         
             
            		module InstanceMethods
         
     | 
| 
       31 
22 
     | 
    
         
             
            			def braintree_customer_attributes
         
     | 
| 
       32 
23 
     | 
    
         
             
            				wanted_attributes = Braintree::Customer._create_signature.reject{|a| a.is_a? Hash}.reject{|a| a == :id}
         
     | 
| 
       33 
     | 
    
         
            -
            				attributes.symbolize_keys. 
     | 
| 
      
 24 
     | 
    
         
            +
            				attributes.symbolize_keys.inject({}) do |rewritten_hash, (original_key, value)|
         
     | 
| 
      
 25 
     | 
    
         
            +
            					rewritten_hash[self.class.braintree_customer.fetch(original_key, original_key)] = value
         
     | 
| 
      
 26 
     | 
    
         
            +
            					rewritten_hash
         
     | 
| 
      
 27 
     | 
    
         
            +
            				end.reject{|key, value| !wanted_attributes.include?(key)}
         
     | 
| 
       34 
28 
     | 
    
         
             
            			end
         
     | 
| 
       35 
29 
     | 
    
         
             
            			def customer
         
     | 
| 
       36 
30 
     | 
    
         
             
            				Braintree::Customer.find(customer_id)
         
     | 
    
        data/redline.gemspec
    CHANGED
    
    | 
         @@ -5,13 +5,13 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{redline}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.1. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.1.2"
         
     | 
| 
       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 
12 
     | 
    
         
             
              s.date = %q{2010-01-19}
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.description = %q{Manual subscriptions via the Braintree gem}
         
     | 
| 
       14 
     | 
    
         
            -
              s.email = %q{james@ 
     | 
| 
      
 14 
     | 
    
         
            +
              s.email = %q{james@marginleft.com}
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
| 
       16 
16 
     | 
    
         
             
                "LICENSE",
         
     | 
| 
       17 
17 
     | 
    
         
             
                 "README.rdoc"
         
     | 
| 
         @@ -25,6 +25,10 @@ Gem::Specification.new do |s| 
     | 
|
| 
       25 
25 
     | 
    
         
             
                 "VERSION",
         
     | 
| 
       26 
26 
     | 
    
         
             
                 "lib/redline.rb",
         
     | 
| 
       27 
27 
     | 
    
         
             
                 "redline.gemspec",
         
     | 
| 
      
 28 
     | 
    
         
            +
                 "spec/db/database.yml",
         
     | 
| 
      
 29 
     | 
    
         
            +
                 "spec/db/models.rb",
         
     | 
| 
      
 30 
     | 
    
         
            +
                 "spec/db/schema.rb",
         
     | 
| 
      
 31 
     | 
    
         
            +
                 "spec/db/test.sqlite3",
         
     | 
| 
       28 
32 
     | 
    
         
             
                 "spec/redline_spec.rb",
         
     | 
| 
       29 
33 
     | 
    
         
             
                 "spec/spec.opts",
         
     | 
| 
       30 
34 
     | 
    
         
             
                 "spec/spec_helper.rb"
         
     | 
| 
         @@ -35,7 +39,9 @@ Gem::Specification.new do |s| 
     | 
|
| 
       35 
39 
     | 
    
         
             
              s.rubygems_version = %q{1.3.5}
         
     | 
| 
       36 
40 
     | 
    
         
             
              s.summary = %q{Braintree via redline: riding the rails}
         
     | 
| 
       37 
41 
     | 
    
         
             
              s.test_files = [
         
     | 
| 
       38 
     | 
    
         
            -
                "spec/ 
     | 
| 
      
 42 
     | 
    
         
            +
                "spec/db/models.rb",
         
     | 
| 
      
 43 
     | 
    
         
            +
                 "spec/db/schema.rb",
         
     | 
| 
      
 44 
     | 
    
         
            +
                 "spec/redline_spec.rb",
         
     | 
| 
       39 
45 
     | 
    
         
             
                 "spec/spec_helper.rb"
         
     | 
| 
       40 
46 
     | 
    
         
             
              ]
         
     | 
| 
       41 
47 
     | 
    
         | 
| 
         @@ -47,15 +53,18 @@ Gem::Specification.new do |s| 
     | 
|
| 
       47 
53 
     | 
    
         
             
                  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
         
     | 
| 
       48 
54 
     | 
    
         
             
                  s.add_development_dependency(%q<braintree>, [">= 0"])
         
     | 
| 
       49 
55 
     | 
    
         
             
                  s.add_development_dependency(%q<activerecord>, [">= 0"])
         
     | 
| 
      
 56 
     | 
    
         
            +
                  s.add_development_dependency(%q<activesupport>, [">= 0"])
         
     | 
| 
       50 
57 
     | 
    
         
             
                else
         
     | 
| 
       51 
58 
     | 
    
         
             
                  s.add_dependency(%q<rspec>, [">= 1.2.9"])
         
     | 
| 
       52 
59 
     | 
    
         
             
                  s.add_dependency(%q<braintree>, [">= 0"])
         
     | 
| 
       53 
60 
     | 
    
         
             
                  s.add_dependency(%q<activerecord>, [">= 0"])
         
     | 
| 
      
 61 
     | 
    
         
            +
                  s.add_dependency(%q<activesupport>, [">= 0"])
         
     | 
| 
       54 
62 
     | 
    
         
             
                end
         
     | 
| 
       55 
63 
     | 
    
         
             
              else
         
     | 
| 
       56 
64 
     | 
    
         
             
                s.add_dependency(%q<rspec>, [">= 1.2.9"])
         
     | 
| 
       57 
65 
     | 
    
         
             
                s.add_dependency(%q<braintree>, [">= 0"])
         
     | 
| 
       58 
66 
     | 
    
         
             
                s.add_dependency(%q<activerecord>, [">= 0"])
         
     | 
| 
      
 67 
     | 
    
         
            +
                s.add_dependency(%q<activesupport>, [">= 0"])
         
     | 
| 
       59 
68 
     | 
    
         
             
              end
         
     | 
| 
       60 
69 
     | 
    
         
             
            end
         
     | 
| 
       61 
70 
     | 
    
         | 
    
        data/spec/db/models.rb
    ADDED
    
    | 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class User < ActiveRecord::Base
         
     | 
| 
      
 2 
     | 
    
         
            +
            	
         
     | 
| 
      
 3 
     | 
    
         
            +
            	acts_as_braintree_customer
         
     | 
| 
      
 4 
     | 
    
         
            +
            	
         
     | 
| 
      
 5 
     | 
    
         
            +
            	validates_presence_of :first_name, :last_name, :unused_attribute, :email
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            class ComplexUser < ActiveRecord::Base
         
     | 
| 
      
 10 
     | 
    
         
            +
            	
         
     | 
| 
      
 11 
     | 
    
         
            +
            	acts_as_braintree_customer :firstname => :first_name, :lastname => :last_name
         
     | 
| 
      
 12 
     | 
    
         
            +
            	
         
     | 
| 
      
 13 
     | 
    
         
            +
            	validates_presence_of :firstname, :lastname, :unused_attribute, :email
         
     | 
| 
      
 14 
     | 
    
         
            +
            	
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/db/schema.rb
    ADDED
    
    | 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ActiveRecord::Schema.define(:version => 1) do
         
     | 
| 
      
 2 
     | 
    
         
            +
              create_table :users, :force => true do |t|
         
     | 
| 
      
 3 
     | 
    
         
            +
                t.column :first_name, :string
         
     | 
| 
      
 4 
     | 
    
         
            +
                t.column :last_name, :string
         
     | 
| 
      
 5 
     | 
    
         
            +
                t.column :email, :string
         
     | 
| 
      
 6 
     | 
    
         
            +
                t.column :unused_attribute, :string
         
     | 
| 
      
 7 
     | 
    
         
            +
                t.column :customer_id, :integer
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
              create_table :complex_users, :force => true do |t|
         
     | 
| 
      
 10 
     | 
    
         
            +
                t.column :firstname, :string
         
     | 
| 
      
 11 
     | 
    
         
            +
                t.column :lastname, :string
         
     | 
| 
      
 12 
     | 
    
         
            +
                t.column :email, :string
         
     | 
| 
      
 13 
     | 
    
         
            +
                t.column :unused_attribute, :string
         
     | 
| 
      
 14 
     | 
    
         
            +
                t.column :customer_id, :integer
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
         Binary file 
     | 
    
        data/spec/redline_spec.rb
    CHANGED
    
    | 
         @@ -1,7 +1,70 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            describe  
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe User do
         
     | 
| 
      
 4 
     | 
    
         
            +
            	
         
     | 
| 
      
 5 
     | 
    
         
            +
            	def valid_user
         
     | 
| 
      
 6 
     | 
    
         
            +
            		Braintree::Customer.stub!('_create_signature').and_return([:first_name, :last_name, :email])
         
     | 
| 
      
 7 
     | 
    
         
            +
            		@user ||= User.new(
         
     | 
| 
      
 8 
     | 
    
         
            +
            			:first_name => 'James', 
         
     | 
| 
      
 9 
     | 
    
         
            +
            			:last_name => 'Daniels', 
         
     | 
| 
      
 10 
     | 
    
         
            +
            			:email => 'james@marginleft.com', 
         
     | 
| 
      
 11 
     | 
    
         
            +
            			:unused_attribute => 'unused'
         
     | 
| 
      
 12 
     | 
    
         
            +
            		)
         
     | 
| 
      
 13 
     | 
    
         
            +
            	end
         
     | 
| 
      
 14 
     | 
    
         
            +
            	
         
     | 
| 
      
 15 
     | 
    
         
            +
            	def mock_customer
         
     | 
| 
      
 16 
     | 
    
         
            +
            		@customer ||= mock(Braintree::Customer, :id => 1)
         
     | 
| 
      
 17 
     | 
    
         
            +
            	end
         
     | 
| 
      
 18 
     | 
    
         
            +
            	
         
     | 
| 
      
 19 
     | 
    
         
            +
            	it "should have a empty braintree_customer" do
         
     | 
| 
      
 20 
     | 
    
         
            +
            		User.braintree_customer.should eql({})
         
     | 
| 
      
 21 
     | 
    
         
            +
            	end
         
     | 
| 
      
 22 
     | 
    
         
            +
              it "should inherit the instance methods" do
         
     | 
| 
      
 23 
     | 
    
         
            +
            		expected_methods = %w(braintree_customer_attributes customer create_customer update_customer delete_customer)
         
     | 
| 
      
 24 
     | 
    
         
            +
            		(User.instance_methods & expected_methods).sort.should eql(expected_methods.sort)
         
     | 
| 
      
 25 
     | 
    
         
            +
            	end
         
     | 
| 
      
 26 
     | 
    
         
            +
            	it "should have proper braintree attributes" do
         
     | 
| 
      
 27 
     | 
    
         
            +
            		valid_user.braintree_customer_attributes.should eql({:first_name=>"James", :last_name=>"Daniels", :email=>"james@marginleft.com"})
         
     | 
| 
      
 28 
     | 
    
         
            +
            	end
         
     | 
| 
      
 29 
     | 
    
         
            +
            	it "should fire Braintree::Customer.create!" do
         
     | 
| 
      
 30 
     | 
    
         
            +
            		Braintree::Customer.should_receive('create!').with(valid_user.braintree_customer_attributes).and_return(mock_customer)
         
     | 
| 
      
 31 
     | 
    
         
            +
            		valid_user.save!
         
     | 
| 
      
 32 
     | 
    
         
            +
            		valid_user.customer_id.should eql(mock_customer.id)
         
     | 
| 
      
 33 
     | 
    
         
            +
            	end
         
     | 
| 
      
 34 
     | 
    
         
            +
            	it "should fire Braintree::Customer.update!" do
         
     | 
| 
      
 35 
     | 
    
         
            +
            		Braintree::Customer.stub!('create!').and_return(mock_customer)
         
     | 
| 
      
 36 
     | 
    
         
            +
            		Braintree::Customer.should_receive('update!').with(mock_customer.id, valid_user.braintree_customer_attributes.merge(:email =>  'james@jamesdaniels.net')).and_return(true)
         
     | 
| 
      
 37 
     | 
    
         
            +
            		valid_user.save!
         
     | 
| 
      
 38 
     | 
    
         
            +
            		valid_user.update_attributes(:email => 'james@jamesdaniels.net')
         
     | 
| 
      
 39 
     | 
    
         
            +
            		valid_user.customer_id.should eql(mock_customer.id)
         
     | 
| 
      
 40 
     | 
    
         
            +
            	end
         
     | 
| 
      
 41 
     | 
    
         
            +
            	it "should fire Braintree::Customer.delete" do
         
     | 
| 
      
 42 
     | 
    
         
            +
            		Braintree::Customer.stub!('create!').and_return(mock_customer)
         
     | 
| 
      
 43 
     | 
    
         
            +
            		Braintree::Customer.stub!('find').and_return(true)
         
     | 
| 
      
 44 
     | 
    
         
            +
            		Braintree::Customer.should_receive('delete').with(mock_customer.id).and_return(true)
         
     | 
| 
      
 45 
     | 
    
         
            +
            		valid_user.save!
         
     | 
| 
      
 46 
     | 
    
         
            +
            		valid_user.destroy
         
     | 
| 
      
 47 
     | 
    
         
            +
            	end
         
     | 
| 
      
 48 
     | 
    
         
            +
            	it "should fire Braintree::Customer.find" do
         
     | 
| 
      
 49 
     | 
    
         
            +
            		Braintree::Customer.stub!('create!').and_return(mock_customer)
         
     | 
| 
      
 50 
     | 
    
         
            +
            		Braintree::Customer.stub!('update!').and_return(true)
         
     | 
| 
      
 51 
     | 
    
         
            +
            		Braintree::Customer.should_receive('find').with(mock_customer.id).and_return(true)
         
     | 
| 
      
 52 
     | 
    
         
            +
            		valid_user.save!
         
     | 
| 
      
 53 
     | 
    
         
            +
            		valid_user.customer
         
     | 
| 
      
 54 
     | 
    
         
            +
            	end
         
     | 
| 
       7 
55 
     | 
    
         
             
            end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            describe ComplexUser do
         
     | 
| 
      
 58 
     | 
    
         
            +
            	it "should have a empty braintree_customer" do
         
     | 
| 
      
 59 
     | 
    
         
            +
            		ComplexUser.braintree_customer.should eql({:firstname=>:first_name, :lastname=>:last_name})
         
     | 
| 
      
 60 
     | 
    
         
            +
            	end
         
     | 
| 
      
 61 
     | 
    
         
            +
            	it "should have proper braintree attributes" do
         
     | 
| 
      
 62 
     | 
    
         
            +
            		Braintree::Customer.stub!('_create_signature').and_return([:first_name, :last_name, :email])
         
     | 
| 
      
 63 
     | 
    
         
            +
            		ComplexUser.new(
         
     | 
| 
      
 64 
     | 
    
         
            +
            			:firstname => 'James', 
         
     | 
| 
      
 65 
     | 
    
         
            +
            			:lastname => 'Daniels', 
         
     | 
| 
      
 66 
     | 
    
         
            +
            			:email => 'james@marginleft.com', 
         
     | 
| 
      
 67 
     | 
    
         
            +
            			:unused_attribute => 'unused'
         
     | 
| 
      
 68 
     | 
    
         
            +
            		).braintree_customer_attributes.should eql({:first_name=>"James", :last_name=>"Daniels", :email=>"james@marginleft.com"})
         
     | 
| 
      
 69 
     | 
    
         
            +
            	end
         
     | 
| 
      
 70 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -1,9 +1,30 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            $LOAD_PATH.unshift(File.dirname(__FILE__))
         
     | 
| 
       2 
2 
     | 
    
         
             
            $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'redline'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'active_record'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'active_record/fixtures'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'active_support'
         
     | 
| 
       4 
7 
     | 
    
         
             
            require 'spec'
         
     | 
| 
       5 
8 
     | 
    
         
             
            require 'spec/autorun'
         
     | 
| 
       6 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
            # establish the database connection
         
     | 
| 
      
 11 
     | 
    
         
            +
            ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/db/database.yml'))
         
     | 
| 
      
 12 
     | 
    
         
            +
            ActiveRecord::Base.establish_connection('active_record_merge_test')
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            # load the schema
         
     | 
| 
      
 15 
     | 
    
         
            +
            $stdout = File.open('/dev/null', 'w')
         
     | 
| 
      
 16 
     | 
    
         
            +
            load(File.dirname(__FILE__) + "/db/schema.rb")
         
     | 
| 
      
 17 
     | 
    
         
            +
            $stdout = STDOUT
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            # load the models
         
     | 
| 
      
 20 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/db/models'
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            # Fake Braintree, for stubbing
         
     | 
| 
      
 23 
     | 
    
         
            +
            module Braintree
         
     | 
| 
      
 24 
     | 
    
         
            +
            	class Customer
         
     | 
| 
      
 25 
     | 
    
         
            +
            	end
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       7 
28 
     | 
    
         
             
            Spec::Runner.configure do |config|
         
     | 
| 
       8 
29 
     | 
    
         | 
| 
       9 
30 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: redline
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - James Daniels
         
     | 
| 
         @@ -42,8 +42,18 @@ dependencies: 
     | 
|
| 
       42 
42 
     | 
    
         
             
                  - !ruby/object:Gem::Version 
         
     | 
| 
       43 
43 
     | 
    
         
             
                    version: "0"
         
     | 
| 
       44 
44 
     | 
    
         
             
                version: 
         
     | 
| 
      
 45 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 46 
     | 
    
         
            +
              name: activesupport
         
     | 
| 
      
 47 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 48 
     | 
    
         
            +
              version_requirement: 
         
     | 
| 
      
 49 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 50 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 51 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 52 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 53 
     | 
    
         
            +
                    version: "0"
         
     | 
| 
      
 54 
     | 
    
         
            +
                version: 
         
     | 
| 
       45 
55 
     | 
    
         
             
            description: Manual subscriptions via the Braintree gem
         
     | 
| 
       46 
     | 
    
         
            -
            email: james@ 
     | 
| 
      
 56 
     | 
    
         
            +
            email: james@marginleft.com
         
     | 
| 
       47 
57 
     | 
    
         
             
            executables: []
         
     | 
| 
       48 
58 
     | 
    
         | 
| 
       49 
59 
     | 
    
         
             
            extensions: []
         
     | 
| 
         @@ -60,6 +70,10 @@ files: 
     | 
|
| 
       60 
70 
     | 
    
         
             
            - VERSION
         
     | 
| 
       61 
71 
     | 
    
         
             
            - lib/redline.rb
         
     | 
| 
       62 
72 
     | 
    
         
             
            - redline.gemspec
         
     | 
| 
      
 73 
     | 
    
         
            +
            - spec/db/database.yml
         
     | 
| 
      
 74 
     | 
    
         
            +
            - spec/db/models.rb
         
     | 
| 
      
 75 
     | 
    
         
            +
            - spec/db/schema.rb
         
     | 
| 
      
 76 
     | 
    
         
            +
            - spec/db/test.sqlite3
         
     | 
| 
       63 
77 
     | 
    
         
             
            - spec/redline_spec.rb
         
     | 
| 
       64 
78 
     | 
    
         
             
            - spec/spec.opts
         
     | 
| 
       65 
79 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
         @@ -92,5 +106,7 @@ signing_key: 
     | 
|
| 
       92 
106 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       93 
107 
     | 
    
         
             
            summary: "Braintree via redline: riding the rails"
         
     | 
| 
       94 
108 
     | 
    
         
             
            test_files: 
         
     | 
| 
      
 109 
     | 
    
         
            +
            - spec/db/models.rb
         
     | 
| 
      
 110 
     | 
    
         
            +
            - spec/db/schema.rb
         
     | 
| 
       95 
111 
     | 
    
         
             
            - spec/redline_spec.rb
         
     | 
| 
       96 
112 
     | 
    
         
             
            - spec/spec_helper.rb
         
     |