netsuite_rails 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,11 @@
3
3
  NetSuite.configure do
4
4
  reset!
5
5
 
6
- email ENV['NETSUITE_EMAIL']
7
- password ENV['NETSUITE_PASSWORD']
8
- account ENV['NETSUITE_ACCOUNT']
9
- role ENV['NETSUITE_ROLE']
10
- api_version ENV['NETSUITE_API']
6
+ email ENV['NETSUITE_EMAIL'] if ENV['NETSUITE_EMAIL'].present?
7
+ password ENV['NETSUITE_PASSWORD'] if ENV['NETSUITE_PASSWORD'].present?
8
+ account ENV['NETSUITE_ACCOUNT'] if ENV['NETSUITE_ACCOUNT'].present?
9
+ role ENV['NETSUITE_ROLE'] if ENV['NETSUITE_ROLE'].present?
10
+ api_version ENV['NETSUITE_API'] if ENV['NETSUITE_API'].present?
11
11
  sandbox (ENV['NETSUITE_PRODUCTION'].blank? || ENV['NETSUITE_PRODUCTION'] != 'true')
12
12
 
13
13
  read_timeout 100000
@@ -130,7 +130,8 @@ module NetSuiteRails
130
130
  @netsuite_pulled ||= false
131
131
  end
132
132
 
133
- def netsuite_pull
133
+ def netsuite_pull(opts = {})
134
+ # TODO need to support the opts hash
134
135
  netsuite_extract_from_record(netsuite_pull_record)
135
136
  end
136
137
 
@@ -149,6 +150,7 @@ module NetSuiteRails
149
150
  NetSuiteRails::RecordSync::PushManager.push(self, opts)
150
151
  end
151
152
 
153
+ # TODO move this login into separate service object
152
154
  def netsuite_extract_from_record(netsuite_record)
153
155
  @netsuite_pulling = true
154
156
 
@@ -83,7 +83,7 @@ module NetSuiteRails
83
83
  # You can force sync mode in different envoirnments with the global configuration variables
84
84
 
85
85
  if sync_options[:mode] == :sync || NetSuiteRails::Configuration.netsuite_sync_mode == :sync
86
- local.send(action)
86
+ local.send(action, action_options)
87
87
  else
88
88
  action_options[:modified_fields] = NetSuiteRails::RecordSync::PushManager.modified_local_fields(local).keys
89
89
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "netsuite_rails"
7
- s.version = "0.2.1"
7
+ s.version = "0.2.2"
8
8
  s.authors = ["Michael Bianco"]
9
9
  s.email = ["mike@cliffsidemedia.com"]
10
10
  s.summary = %q{Write Rails applications that integrate with NetSuite}
@@ -8,55 +8,71 @@ describe NetSuiteRails::SyncTrigger do
8
8
  allow(NetSuiteRails::RecordSync::PushManager).to receive(:push_update)
9
9
  end
10
10
 
11
- it "should push new record when saved" do
12
- s = StandardRecord.new
13
- s.phone = Faker::PhoneNumber.phone_number
14
- s.save!
11
+ context 'push' do
12
+ it "should push new record when saved" do
13
+ s = StandardRecord.new
14
+ s.phone = Faker::PhoneNumber.phone_number
15
+ s.save!
15
16
 
16
- expect(NetSuiteRails::RecordSync::PushManager).to have_received(:push_add)
17
- expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_update)
18
- end
17
+ expect(NetSuiteRails::RecordSync::PushManager).to have_received(:push_add)
18
+ expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_update)
19
+ end
19
20
 
20
- it "should not push update on a pull record" do
21
- s = StandardRecord.new netsuite_id: 123
22
- allow(s).to receive(:netsuite_pull)
23
- s.save!
21
+ it "should not push update on a pull record" do
22
+ s = StandardRecord.new netsuite_id: 123
23
+ allow(s).to receive(:netsuite_pull)
24
+ s.save!
24
25
 
25
- expect(s).to have_received(:netsuite_pull)
26
- expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_add)
27
- expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_update)
28
- end
26
+ expect(s).to have_received(:netsuite_pull)
27
+ expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_add)
28
+ expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_update)
29
+ end
29
30
 
30
- it "should push an update on an existing record" do
31
- s = StandardRecord.new netsuite_id: 123
32
- allow(s).to receive(:netsuite_pull)
33
- s.save!
31
+ it "should push an update on an existing record" do
32
+ s = StandardRecord.new netsuite_id: 123
33
+ allow(s).to receive(:netsuite_pull)
34
+ s.save!
34
35
 
35
- s.phone = Faker::PhoneNumber.phone_number
36
- s.save!
36
+ s.phone = Faker::PhoneNumber.phone_number
37
+ s.save!
37
38
 
38
- expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_add)
39
- expect(NetSuiteRails::RecordSync::PushManager).to have_received(:push_update)
40
- end
39
+ expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_add)
40
+ expect(NetSuiteRails::RecordSync::PushManager).to have_received(:push_update)
41
+ end
42
+
43
+ it "should push the modified attributes to the model" do
44
+ s = StandardRecord.new netsuite_id: 123
45
+ allow(s).to receive(:netsuite_pull)
46
+ s.save!
41
47
 
42
- it "should push the modified attributes to the model" do
43
- s = StandardRecord.new netsuite_id: 123
44
- allow(s).to receive(:netsuite_pull)
45
- s.save!
48
+ # delayed_job isn't included in this gem; hack it into the current record instance
49
+ s.instance_eval { def delay; self; end }
50
+ allow(s).to receive(:delay).and_return(s)
46
51
 
47
- # delayed_job isn't included in this gem; hack it into the current record instance
48
- s.instance_eval { def delay; self; end }
49
- allow(s).to receive(:delay).and_return(s)
52
+ NetSuiteRails::Configuration.netsuite_sync_mode :async
50
53
 
51
- NetSuiteRails::Configuration.netsuite_sync_mode :async
54
+ s.phone = Faker::PhoneNumber.phone_number
55
+ s.save!
56
+
57
+ NetSuiteRails::Configuration.netsuite_sync_mode :sync
58
+
59
+ expect(s).to have_received(:delay)
60
+ expect(NetSuiteRails::RecordSync::PushManager).to have_received(:push_update).with(anything, anything, {:modified_fields=>{:phone=> :phone}})
61
+ end
62
+ end
52
63
 
53
- s.phone = Faker::PhoneNumber.phone_number
54
- s.save!
64
+ context 'pull' do
65
+ it 'should pull down a new record with a NS ID set on save' do
66
+ s = StandardRecord.new netsuite_id: 123
67
+ allow(s).to receive(:netsuite_pull_record).and_return(NetSuite::Records::Customer.new(phone: '1231231234'))
68
+ allow(s).to receive(:netsuite_extract_from_record)
55
69
 
56
- NetSuiteRails::Configuration.netsuite_sync_mode :sync
70
+ s.save!
57
71
 
58
- expect(s).to have_received(:delay)
59
- expect(NetSuiteRails::RecordSync::PushManager).to have_received(:push_update).with(anything, anything, {:modified_fields=>{:phone=> :phone}})
72
+ expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_add)
73
+ expect(NetSuiteRails::RecordSync::PushManager).to_not have_received(:push_update)
74
+ expect(s).to have_received(:netsuite_extract_from_record)
75
+ end
60
76
  end
61
77
 
62
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsuite_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-13 00:00:00.000000000 Z
12
+ date: 2015-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: netsuite