highrise_mapper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,6 @@
1
1
  .DS_Store
2
2
  pkg
3
3
  tmp
4
+
5
+ #where I keep my 'export's for HIGHRISE_TOKEN and HIGHRISE_BASE_URL
6
+ env.bash
@@ -1,3 +1,5 @@
1
1
  rvm:
2
2
  - 2.0.0
3
- - 1.9.3
3
+ - 1.9.3
4
+ before_install:
5
+ - gem install bundler
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ highrise_mapper (0.0.2)
5
+ highrise (~> 3.1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (4.0.0)
11
+ activesupport (= 4.0.0)
12
+ builder (~> 3.1.0)
13
+ erubis (~> 2.7.0)
14
+ rack (~> 1.5.2)
15
+ rack-test (~> 0.6.2)
16
+ activemodel (4.0.0)
17
+ activesupport (= 4.0.0)
18
+ builder (~> 3.1.0)
19
+ activeresource (4.0.0)
20
+ activemodel (~> 4.0)
21
+ activesupport (~> 4.0)
22
+ rails-observers (~> 0.1.1)
23
+ activesupport (4.0.0)
24
+ i18n (~> 0.6, >= 0.6.4)
25
+ minitest (~> 4.2)
26
+ multi_json (~> 1.3)
27
+ thread_safe (~> 0.1)
28
+ tzinfo (~> 0.3.37)
29
+ atomic (1.1.10)
30
+ builder (3.1.4)
31
+ coderay (1.0.9)
32
+ diff-lcs (1.2.4)
33
+ erubis (2.7.0)
34
+ highrise (3.1.0)
35
+ activeresource (~> 4.0.0)
36
+ i18n (0.6.4)
37
+ method_source (0.8.1)
38
+ minitest (4.7.5)
39
+ multi_json (1.7.7)
40
+ pry (0.9.12.2)
41
+ coderay (~> 1.0.5)
42
+ method_source (~> 0.8)
43
+ slop (~> 3.4)
44
+ pry-nav (0.2.3)
45
+ pry (~> 0.9.10)
46
+ rack (1.5.2)
47
+ rack-test (0.6.2)
48
+ rack (>= 1.0)
49
+ rails-observers (0.1.1)
50
+ railties (~> 4.0.0.beta)
51
+ railties (4.0.0)
52
+ actionpack (= 4.0.0)
53
+ activesupport (= 4.0.0)
54
+ rake (>= 0.8.7)
55
+ thor (>= 0.18.1, < 2.0)
56
+ rake (10.0.4)
57
+ rspec (2.13.0)
58
+ rspec-core (~> 2.13.0)
59
+ rspec-expectations (~> 2.13.0)
60
+ rspec-mocks (~> 2.13.0)
61
+ rspec-core (2.13.1)
62
+ rspec-expectations (2.13.0)
63
+ diff-lcs (>= 1.1.3, < 2.0)
64
+ rspec-mocks (2.13.1)
65
+ slop (3.4.5)
66
+ thor (0.18.1)
67
+ thread_safe (0.1.0)
68
+ atomic
69
+ tzinfo (0.3.37)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ highrise_mapper!
76
+ pry
77
+ pry-nav
78
+ rake
79
+ rspec
80
+ rspec-mocks
data/Rakefile CHANGED
@@ -4,4 +4,12 @@ Bundler::GemHelper.install_tasks
4
4
  require "rspec/core/rake_task"
5
5
  RSpec::Core::RakeTask.new
6
6
 
7
- task :default => :build
7
+ task :default => :travis
8
+
9
+ task :travis do
10
+ ["rake spec", "rake build"].each do |cmd|
11
+ puts "Starting to run #{cmd}..."
12
+ system("export DISPLAY=:99.0 && bundle exec #{cmd}")
13
+ raise "#{cmd} failed!" unless $?.exitstatus == 0
14
+ end
15
+ end
data/Readme.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Code Climate](https://codeclimate.com/github/lucasmartins/highrise-mapper.png)](https://codeclimate.com/github/lucasmartins/highrise-mapper) [![Build Status](https://secure.travis-ci.org/lucasmartins/highrise-mapper.png?branch=master)](https://travis-ci.org/lucasmartins/highrise-mapper) [![Dependency Status](https://gemnasium.com/lucasmartins/highrise-mapper.png)](https://gemnasium.com/lucasmartins/highrise-mapper)
1
+ [![Gem version](https://badge.fury.io/rb/highrise_mapper.png)](http://rubygems.org/gems/highrise_mapper) [![Code Climate](https://codeclimate.com/github/lucasmartins/highrise-mapper.png)](https://codeclimate.com/github/lucasmartins/highrise-mapper) [![Build Status](https://secure.travis-ci.org/lucasmartins/highrise-mapper.png?branch=master)](https://travis-ci.org/lucasmartins/highrise-mapper) [![Dependency Status](https://gemnasium.com/lucasmartins/highrise-mapper.png)](https://gemnasium.com/lucasmartins/highrise-mapper)
2
2
 
3
3
  Highrise Mapper
4
4
  ===============
@@ -40,6 +40,12 @@ person:
40
40
  company_name: company_name
41
41
  email_address: email
42
42
  ```
43
+ Non-Railers should call `HighriseMapper.config(root_directory)` on application bootstrap, where it will be mapped like this:
44
+ ```ruby
45
+ "#{root_dir}/config/highrise_mapper.yml"
46
+ ```
47
+
48
+ ### Your model
43
49
 
44
50
  In this example, you could have a Person class like this one:
45
51
 
@@ -62,14 +68,81 @@ class Person
62
68
  end
63
69
  end
64
70
  ```
71
+ ### HighriseMapper::Person
72
+
73
+ When including, the module `HighriseMapper::Person` will check for expected behavior from your class, so you will have to make some changes:
74
+
75
+ ```ruby
76
+ class Person
77
+ def name
78
+ 'Albert'
79
+ end
80
+
81
+ def last_name
82
+ 'Einstein'
83
+ end
84
+
85
+ def company_name
86
+ self.company.name
87
+ end
88
+
89
+ def email
90
+ 'albert.einstein@princeton.edu'
91
+ end
92
+
93
+ def highrise_context
94
+ #must return an instance that includes HighriseMapper::Context
95
+ self.highrise_account
96
+ end
97
+
98
+ def highrise_id
99
+ #must return the id this object has in Highrise
100
+ 112233
101
+ end
102
+
103
+ #must be included after required behavior has been added to the Class
104
+ include HighriseMapper::Person
105
+ end
106
+ ```
107
+
108
+ Check the [specs](https://github.com/lucasmartins/highrise-mapper/tree/master/spec) to see the testing example, it will surely make it clearer.
109
+
65
110
  Notice that this implementation is database agnostic, there is no database reference whatsoever.
66
111
 
67
- Check the specs to see the testing example.
112
+ Checkout the [sample rails application](https://github.com/lucasmartins/highrise-mapper-example).
113
+
114
+ ### HighriseMapper::Context
115
+
116
+ When saving to Highrise, `HighriseMapper::Person` will look for the **base url** and **token** to connect to the right account, so you must have a model that represents this account configuration:
117
+
118
+ ```ruby
119
+ class SaasCustomer
120
+ def name
121
+ 'Rails na Praia'
122
+ end
123
+
124
+ def highrise_base_url
125
+ 'https://railsnapraia.highrisehq.com'
126
+ end
127
+
128
+ def highrise_token
129
+ 'a11386d68bdd94fe549b8498afafce56'
130
+ end
131
+ #must be included after required behavior has been added to the Class
132
+ include HighriseMapper::Context
133
+ end
134
+ ```
135
+
136
+ It is designed this way so your SaaS application (example) can connect to multiple Highrise accounts, then we can have an ERP/CRM SaaS application where each customer sets up their own Highrise account.
137
+
138
+ Again, check the [specs](https://github.com/lucasmartins/highrise-mapper/tree/master/spec) and the [sample rails application](https://github.com/lucasmartins/highrise-mapper-example).
68
139
 
69
140
  Contribute
70
141
  ==========
71
142
 
72
- Just fork [HighriseMapper](https://github.com/lucasmartins/highrise-mapper), add your feature+spec, and make a pull request.
143
+ Just fork [HighriseMapper](https://github.com/lucasmartins/highrise-mapper), add your feature+spec, and make a pull request. Do not mess up with the version file though.
144
+
145
+ Also, if needed, update the code of the [sample application](https://github.com/lucasmartins/highrise-mapper-example).
73
146
 
74
147
  Support
75
148
  =======
@@ -79,4 +152,4 @@ This is an opensource project so don't expect premium support, but don't be shy,
79
152
  License
80
153
  =======
81
154
 
82
- Tacape Tools is free software under the [MIT license](http://lucasmartins.mit-license.org).
155
+ Highrise Mapper is free software under the [MIT license](http://lucasmartins.mit-license.org).
@@ -19,9 +19,10 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "highrise-rails4"
22
+ s.add_dependency "highrise", "~>3.1.0"
23
23
 
24
24
  s.add_development_dependency "rspec"
25
+ s.add_development_dependency "rspec-mocks"
25
26
  s.add_development_dependency "rake"
26
27
  s.add_development_dependency "pry"
27
28
  s.add_development_dependency "pry-nav"
@@ -1,9 +1,6 @@
1
1
  module HighriseMapper
2
2
  module Context
3
3
 
4
- module ClassMethods
5
- end
6
-
7
4
  module InstanceMethods
8
5
  def setup_highrise
9
6
  Highrise::Base.site = self.highrise_base_url
@@ -13,7 +10,6 @@ module HighriseMapper
13
10
  end
14
11
 
15
12
  def self.included(receiver)
16
- receiver.extend ClassMethods
17
13
  receiver.send :include, InstanceMethods
18
14
  check_expected_behavior(receiver)
19
15
  end
@@ -1,8 +1,5 @@
1
1
  module HighriseMapper
2
2
  module Person
3
-
4
- module ClassMethods
5
- end
6
3
 
7
4
  module InstanceMethods
8
5
  def save_to_highrise
@@ -50,7 +47,6 @@ module HighriseMapper
50
47
  end
51
48
 
52
49
  def self.included(receiver)
53
- receiver.extend ClassMethods
54
50
  receiver.send :include, InstanceMethods
55
51
  check_expected_behavior(receiver)
56
52
  end
@@ -2,7 +2,7 @@ module HighriseMapper
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 2
5
+ PATCH = 3
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -1,6 +1,4 @@
1
1
  require "spec_helper"
2
- require 'pry'
3
- require 'pry-nav'
4
2
 
5
3
  describe HighriseMapper, "::config" do
6
4
  it "returns a valid configuration Hash" do
@@ -1,26 +1,29 @@
1
1
  require "spec_helper"
2
2
 
3
- describe HighriseMapper::Person, "#save_to_highrise" do
4
- it "persists the Highrise::Person successfully" do
5
- HighriseMapper.config('templates')
6
- contact = Contact.new
7
- begin
8
- result = contact.save_to_highrise
9
- result.should be_a_kind_of(Fixnum)
10
- ensure
11
- Highrise::Person.find(result).destroy
3
+ if highrise_env_available?
4
+ describe HighriseMapper::Person, "#save_to_highrise" do
5
+ it "persists the Highrise::Person successfully" do
6
+ HighriseMapper.config('templates')
7
+ contact = Contact.new
8
+ begin
9
+ result = contact.save_to_highrise
10
+ result.should be_a_kind_of(Fixnum)
11
+ ensure
12
+ Highrise::Person.find(result).destroy
13
+ end
12
14
  end
13
15
  end
14
- end
15
16
 
16
- describe HighriseMapper::Person, "#delete_from_highrise" do
17
- it "deletes the Highrise::Person successfully" do
18
- HighriseMapper.config('templates')
19
- contact = Contact.new
20
- highrise_person_id = contact.save_to_highrise
21
- result = contact.delete_from_highrise(highrise_person_id)
22
- result.should be_a_kind_of(Net::HTTPOK)
17
+ describe HighriseMapper::Person, "#delete_from_highrise" do
18
+ it "deletes the Highrise::Person successfully" do
19
+ HighriseMapper.config('templates')
20
+ contact = Contact.new
21
+ highrise_person_id = contact.save_to_highrise
22
+ result = contact.delete_from_highrise(highrise_person_id)
23
+ result.should be_a_kind_of(Net::HTTPOK)
24
+ end
23
25
  end
24
- end
25
-
26
-
26
+ else
27
+ describe HighriseMapper::Person, "#save_to_highrise"
28
+ describe HighriseMapper::Person, "#delete_from_highrise"
29
+ end
@@ -1,4 +1,8 @@
1
+ require 'pry'
2
+ require 'pry-nav'
1
3
  require "highrise_mapper"
4
+ require 'rspec'
5
+ require 'rspec/mocks'
2
6
  require "pathname"
3
7
 
4
8
  SPECDIR = Pathname.new(File.dirname(__FILE__))
@@ -7,7 +11,14 @@ TMPDIR = SPECDIR.join("tmp")
7
11
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|r| require r}
8
12
 
9
13
  RSpec.configure do |config|
10
- config.include(SpecHelper)
11
-
12
14
  config.before { FileUtils.mkdir_p(TMPDIR) }
13
15
  end
16
+
17
+ def highrise_env_available?
18
+ if ENV['HIGHRISE_TOKEN']!=nil && ENV['HIGHRISE_BASE_URL']!=nil && ENV['HIGHRISE_TOKEN']!='' && ENV['HIGHRISE_BASE_URL']!=''
19
+ return true
20
+ else
21
+ puts 'INFO: No Highrise TOKEN/BASEURL environment variable defined, tests regarding HTTP communication will be ignored.'
22
+ return false
23
+ end
24
+ end
@@ -1,4 +1,5 @@
1
1
  class Contact
2
+ extend RSpec::Mocks
2
3
  def name
3
4
  'Albert'
4
5
  end
@@ -16,7 +17,11 @@ class Contact
16
17
  end
17
18
 
18
19
  def highrise_context
19
- SaasCustomer.new
20
+ @saas_customer = SaasCustomer.new
21
+ @saas_customer.stub(highrise_base_url: 'Rails on the beach' )
22
+ @saas_customer.stub(highrise_base_url: ENV['HIGHRISE_BASE_URL'] )
23
+ @saas_customer.stub(highrise_token: ENV['HIGHRISE_TOKEN'] )
24
+ return @saas_customer
20
25
  end
21
26
 
22
27
  def highrise_id
@@ -1,15 +1,14 @@
1
1
  class SaasCustomer
2
+ # check the mock in the contact.rb for more information on how this model should behave
2
3
  def name
3
- 'Rails na Praia'
4
4
  end
5
5
 
6
6
  def highrise_base_url
7
- 'https://railsnapraia.highrisehq.com'
8
7
  end
9
8
 
10
9
  def highrise_token
11
- 'a11386d68bdd94fe549b8498afafce56'
12
10
  end
11
+
13
12
  #must be included after required behavior has been added to the Class
14
13
  include HighriseMapper::Context
15
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highrise_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,17 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-18 00:00:00.000000000 Z
12
+ date: 2013-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: highrise-rails4
15
+ name: highrise
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
16
32
  requirement: !ruby/object:Gem::Requirement
17
33
  none: false
18
34
  requirements:
19
35
  - - ! '>='
20
36
  - !ruby/object:Gem::Version
21
37
  version: '0'
22
- type: :runtime
38
+ type: :development
23
39
  prerelease: false
24
40
  version_requirements: !ruby/object:Gem::Requirement
25
41
  none: false
@@ -28,7 +44,7 @@ dependencies:
28
44
  - !ruby/object:Gem::Version
29
45
  version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
- name: rspec
47
+ name: rspec-mocks
32
48
  requirement: !ruby/object:Gem::Requirement
33
49
  none: false
34
50
  requirements:
@@ -102,6 +118,7 @@ files:
102
118
  - .rspec
103
119
  - .travis.yml
104
120
  - Gemfile
121
+ - Gemfile.lock
105
122
  - Rakefile
106
123
  - Readme.md
107
124
  - config/locales/en.yml
@@ -117,7 +134,6 @@ files:
117
134
  - spec/person_spec.rb
118
135
  - spec/spec_helper.rb
119
136
  - spec/support/contact.rb
120
- - spec/support/helper.rb
121
137
  - spec/support/saas_customer.rb
122
138
  - templates/config/highrise_mapper.yml
123
139
  homepage: http://rubygems.org/gems/highrise-mapper
@@ -150,6 +166,5 @@ test_files:
150
166
  - spec/person_spec.rb
151
167
  - spec/spec_helper.rb
152
168
  - spec/support/contact.rb
153
- - spec/support/helper.rb
154
169
  - spec/support/saas_customer.rb
155
170
  has_rdoc:
@@ -1,3 +0,0 @@
1
- module SpecHelper
2
-
3
- end