netsuite_rails 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02de40385dbc5f58b5ff3e4f5a30d5d861e6d6e8
4
- data.tar.gz: 6f7428c068be19459b754c577b6cbecff2e7ac25
3
+ metadata.gz: f2f2197544aa8884365eda94c0b6d23069430e0e
4
+ data.tar.gz: 65012b398bc868048b9de452df38820ac102f383
5
5
  SHA512:
6
- metadata.gz: 9ed7e6ee9237efe96e3a4930085773b0cd0b689844eb9ab3dfe0ec23bb2bed3c42023a28feaf7305cb79052f8388f4069acf3c9ce7cdf68f6945b1b648b02dfb
7
- data.tar.gz: 35ab8e616e0f090aff659ea5564b918b00720da78de6404534f5b3dd5dc82d634d79ccedf5387544d3edade71a9c874d230a4c709ec86e646de5ef3920e89a86
6
+ metadata.gz: c486c007a6d97f0633e82a2d37a7b57321de8115e0a99c80331978b86137b649820bc7bd28c17c6223adfaca23ccf11c1df2fcf2cc1dca4f8409362cdce2b6f2
7
+ data.tar.gz: 87ef0a329e7ed7af87244d1b058dde0f390e5d887628dc200ee0f49c8d79f4aec525c879da73111003ced628549294d35261315adf0c453e0c0d27264b073423
data/Gemfile CHANGED
@@ -11,7 +11,4 @@ group :test do
11
11
 
12
12
  gem 'rspec-rails', '~> 3.4.2'
13
13
  gem 'pry-nav'
14
-
15
- gem 'rerun'
16
- gem 'rb-fsevent'
17
14
  end
@@ -18,6 +18,8 @@ module NetSuiteRails
18
18
 
19
19
  cattr_accessor :netsuite_custom_record_type_id
20
20
  cattr_accessor :netsuite_sync_options
21
+
22
+ self.netsuite_sync_options = {}
21
23
  end
22
24
 
23
25
  klass.send(:extend, ClassMethods)
@@ -60,7 +60,7 @@ module NetSuiteRails
60
60
  search_criteria = {
61
61
  criteria: {
62
62
  basic: poll_basic_criteria(klass, opts)
63
- }
63
+ }.merge(poll_join_criteria(klass, opts))
64
64
  }
65
65
 
66
66
  if opts[:saved_search_id]
@@ -85,7 +85,7 @@ module NetSuiteRails
85
85
  }.merge(opts)
86
86
 
87
87
  # allow custom criteria to be passed directly to the sync call
88
- criteria = opts[:criteria] || []
88
+ criteria = extract_basic_search_criteria(opts[:criteria])
89
89
 
90
90
  # allow custom criteria from the model level
91
91
  criteria += klass.netsuite_sync_options[:criteria] || []
@@ -112,6 +112,35 @@ module NetSuiteRails
112
112
  criteria
113
113
  end
114
114
 
115
+ def poll_join_criteria(klass, opts)
116
+ extract_advanced_search_criteria(opts[:criteria])
117
+ end
118
+
119
+ def extract_advanced_search_criteria(criteria_option)
120
+ if criteria_option.is_a?(Hash)
121
+ criteria_option = criteria_option.dup
122
+ criteria_option.delete(:basic)
123
+
124
+ criteria_option
125
+ elsif criteria_option.is_a?(Array) || criteria_option.nil?
126
+ {}
127
+ else
128
+ # TODO unhandled criteria type
129
+ end
130
+ end
131
+
132
+ def extract_basic_search_criteria(criteria_option)
133
+ # TODO use `kind_of?` instead?
134
+
135
+ if criteria_option.is_a?(Hash)
136
+ criteria_option[:basic] || []
137
+ elsif criteria_option.is_a?(Array)
138
+ criteria_option
139
+ else
140
+ # TODO unhandled criteria class
141
+ end
142
+ end
143
+
115
144
  def process_search_results(klass, opts, search)
116
145
  opts = {
117
146
  skip_existing: false,
@@ -79,6 +79,7 @@ module NetSuiteRails
79
79
 
80
80
  sync_options = local.netsuite_sync_options
81
81
 
82
+ # TODO should migrate to push_if for better self-documentation
82
83
  # :if option is a block that returns a boolean
83
84
  return if sync_options.has_key?(:if) && !local.instance_exec(&sync_options[:if])
84
85
 
@@ -49,8 +49,11 @@ module NetSuiteRails
49
49
  return nil
50
50
  end
51
51
 
52
- # an error will be thrown if period is on the end of a sentence
53
- email = email.gsub(/[^A-Za-z]+$/, '')
52
+ email = email.
53
+ # an error will be thrown if period is on the end of a sentence
54
+ gsub(/[^A-Za-z]+$/, '').
55
+ # any commas in the email with throw an error
56
+ gsub(',', '')
54
57
 
55
58
  email
56
59
  else
@@ -62,6 +62,8 @@ module NetSuiteRails
62
62
  "/accounting/transactions/transaction.nl?id=#{internal_id}"
63
63
  elsif NetSuite::Records::Account == record_class
64
64
  "/accounting/account/account.nl?id=#{internal_id}"
65
+ elsif NetSuite::Records::Subsidiary == record_class
66
+ "/common/otherlists/subsidiarytype.nl?id=#{internal_id}"
65
67
  else
66
68
  # TODO unsupported record type error?
67
69
  end
@@ -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.3.3"
7
+ s.version = "0.3.4"
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}
@@ -22,7 +22,8 @@ describe NetSuiteRails::RecordSync::PollManager do
22
22
  end
23
23
 
24
24
  it "should poll list sync objects" do
25
- allow(NetSuite::Records::CustomList).to receive(:get).and_return(OpenStruct.new(custom_value_list: OpenStruct.new(custom_value: [])))
25
+ allow(NetSuite::Records::CustomList).to receive(:get)
26
+ .and_return(OpenStruct.new(custom_value_list: OpenStruct.new(custom_value: [])))
26
27
 
27
28
  StandardList.netsuite_poll(import_all: true)
28
29
 
@@ -51,4 +52,70 @@ describe NetSuiteRails::RecordSync::PollManager do
51
52
 
52
53
  expect(record).to have_received(:netsuite_pull)
53
54
  end
55
+
56
+ describe 'custom search criteria' do
57
+ let(:basic_search_field) do
58
+ {
59
+ field: 'type',
60
+ operator: 'anyOf',
61
+ value: [ '_itemFulfillment' ]
62
+ }
63
+ end
64
+
65
+ let(:advanced_search_criteria) do
66
+ {
67
+ createdFromJoin: [
68
+ {
69
+ field: 'type',
70
+ operator: 'anyOf',
71
+ value: [ '_transferOrder' ]
72
+ }
73
+ ]
74
+ }
75
+ end
76
+
77
+ it 'should merge basic search criteria' do
78
+ expect(NetSuite::Records::Customer).to receive(:search)
79
+ .with(hash_including(
80
+ criteria: hash_including(
81
+ basic: array_including(
82
+ basic_search_field
83
+ )
84
+ )
85
+ ))
86
+ .and_return(OpenStruct.new(results: []))
87
+
88
+ NetSuiteRails::RecordSync::PollManager.poll(StandardRecord,
89
+ criteria: [ basic_search_field ]
90
+ )
91
+ end
92
+
93
+ it 'merges advanced and basic criteria' do
94
+ expect(NetSuite::Records::Customer).to receive(:search)
95
+ .with(hash_including(
96
+ criteria: {
97
+ basic: array_including(
98
+ basic_search_field
99
+ )
100
+ }.merge(advanced_search_criteria)
101
+ ))
102
+ .and_return(OpenStruct.new(results: []))
103
+
104
+ NetSuiteRails::RecordSync::PollManager.poll(StandardRecord,
105
+ criteria: {
106
+ basic: [ basic_search_field ]
107
+ }.merge(advanced_search_criteria)
108
+ )
109
+ end
110
+
111
+ it 'should merge join/advanced criteria' do
112
+ expect(NetSuite::Records::Customer).to receive(:search)
113
+ .with(hash_including(criteria: hash_including(advanced_search_criteria)))
114
+ .and_return(OpenStruct.new(results: []))
115
+
116
+ NetSuiteRails::RecordSync::PollManager.poll(StandardRecord,
117
+ criteria: advanced_search_criteria
118
+ )
119
+ end
120
+ end
54
121
  end
@@ -58,5 +58,9 @@ describe NetSuiteRails::Transformations do
58
58
  netsuite_email = ' example+second@example.family. '
59
59
  transformed_netsuite_email = NetSuiteRails::Transformations.email(netsuite_email, :push)
60
60
  expect(transformed_netsuite_email.to_s).to eq('example+second@example.family')
61
+
62
+ netsuite_email = ' example,second@example.com '
63
+ transformed_netsuite_email = NetSuiteRails::Transformations.email(netsuite_email, :push)
64
+ expect(transformed_netsuite_email.to_s).to eq('examplesecond@example.com')
61
65
  end
62
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsuite_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bianco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-15 00:00:00.000000000 Z
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netsuite