ooor 2.1.0 → 2.2.0

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: 569343208ad336f19ea6a20a6488989c5d1cd965
4
- data.tar.gz: 84e8e8e15cd727a543e8686bf35eac3d3c26e13f
3
+ metadata.gz: d891fa43f53c6874d616400d37c2805cea7ddc1a
4
+ data.tar.gz: 1d8d0f527525a111762c53328307bc5a340dabe4
5
5
  SHA512:
6
- metadata.gz: 45e8b662e1e69562cd9e83890abb520531d671d4d8b7240ec42f702d1ebc775fb9e2870f94dfe46e0d1494781db58522f9cb4dba4cb744320fa5adc0437dd3f5
7
- data.tar.gz: c4200b1ca5fcfdd5bc64a42749d073c71aacbd73a4ad7b68cb6fbbcc8e238144e51170d60d76b4f7ef95678c87d85d6661107f65c467bc26772619ef17d6a8ce
6
+ metadata.gz: bf0f99297dfdc754b059be24b48c2292e7520b43c789c97ec4cf4415826e3a56de0c06ef54777c03c1b8eb8422a060bb3134f96fc2bee781ddd1caf9995b78d3
7
+ data.tar.gz: cc6e0c73cf713dc4ea8d01c6abfaf1c07168d6ec022ffe851443c079c183b1f72a1653e70ebc5197adaa52a3ea04b8dc33811d709abd176ace16abe5b10224f4
data/lib/ooor/errors.rb CHANGED
@@ -25,7 +25,7 @@ module Ooor
25
25
  return ValueError.new(method, faultCode, faultString, *args)
26
26
  elsif faultCode =~ /ValidateError/
27
27
  return ValidationError.new(method, faultCode, faultString, *args)
28
- elsif faultCode =~ /AccessDenied/ || faultCode =~ /Access Denied/
28
+ elsif faultCode =~ /AccessDenied/ || faultCode =~ /Access Denied/ || faultCode =~ /AccessError/
29
29
  return UnAuthorizedError.new(method, faultCode, faultString, *args)
30
30
  elsif faultCode =~ /AuthenticationError: Credentials not provided/
31
31
  return InvalidSessionError.new(method, faultCode, faultString, *args)
@@ -45,7 +45,7 @@ module Ooor
45
45
  end
46
46
 
47
47
  def filter_password(args)
48
- if args[0].is_a?(String) && (args[1].is_a?(Integer) || args[1].to_i != 0) && args[2].is_a?(String)
48
+ if args[0].is_a?(String) && args[2].is_a?(String) && (args[1].is_a?(Integer) || args[1].to_i != 0)
49
49
  args[2] = "####"
50
50
  end
51
51
  args.map! do |arg|
@@ -119,21 +119,20 @@ module Ooor
119
119
 
120
120
  def lazy_load(meth, *args)
121
121
  @lazy = false
122
- load(rpc_execute('read', [id], (self.class.fast_fields + [meth]).uniq, *args || context)[0]).tap do
122
+ fields = (self.class.fast_fields + [meth]).uniq
123
+ load(rpc_execute('read', [@attributes["id"]], fields, *args || context)[0]).tap do
123
124
  @lazy = false
124
125
  end
125
126
  end
126
127
 
127
128
  def get_attribute(meth, *args)
128
- lazy_load(meth, *args) if @lazy
129
+ lazy_load(meth, *args) if @lazy && @attributes["id"]
129
130
  if @attributes.has_key?(meth)
130
131
  @attributes[meth]
131
- else #lazy loading
132
- if @attributes["id"]
133
- @attributes[meth] = rpc_execute('read', [@attributes["id"]], [meth], *args || context)[0][meth]
134
- else
135
- nil
136
- end
132
+ elsif @attributes["id"] # if field is computed for instance
133
+ @attributes[meth] = rpc_execute('read', [@attributes["id"]], [meth], *args || context)[0][meth]
134
+ else
135
+ nil
137
136
  end
138
137
  end
139
138
 
@@ -314,6 +314,21 @@ module Ooor
314
314
 
315
315
  def load_with_defaults(attributes, default_get_list)
316
316
  defaults = rpc_execute("default_get", default_get_list || self.class.fields.keys + self.class.associations_keys, context)
317
+ self.class.associations_keys.each do |k|
318
+ # m2m with existing records:
319
+ if defaults[k].is_a?(Array) && defaults[k][0].is_a?(Array) && defaults[k][0][2].is_a?(Array)
320
+ defaults[k] = defaults[k][0][2]
321
+ # m2m with records to create:
322
+ elsif defaults[k].is_a?(Array) && defaults[k][0].is_a?(Array) && defaults[k][0][2].is_a?(Hash) # TODO make more robust
323
+ defaults[k] = defaults[k].map { |item| self.class.all_fields[k]['relation'].new(item[2]) }
324
+ # strange case with default product taxes on v9
325
+ elsif defaults[k].is_a?(Array) && defaults[k][0] == [5] && defaults[k][1].is_a?(Array)
326
+ defaults[k] = [defaults[k][1].last] # TODO may e more subtle
327
+ # default ResPartners category_id on v9; know why...
328
+ elsif defaults[k].is_a?(Array) && defaults[k][0].is_a?(Array)
329
+ defaults[k] = defaults[k][0]
330
+ end
331
+ end
317
332
  attributes = HashWithIndifferentAccess.new(defaults.merge(attributes.reject {|k, v| v.blank? }))
318
333
  load(attributes)
319
334
  end
@@ -10,6 +10,10 @@ module Ooor
10
10
  self.class.columns_hash[name.to_s]
11
11
  end
12
12
 
13
+ def has_attribute?(attr_name)
14
+ self.class.columns_hash.key?(attr_name.to_s)
15
+ end
16
+
13
17
  module ClassMethods
14
18
  def reflections
15
19
  @reflections ||= {}
data/lib/ooor/services.rb CHANGED
@@ -12,7 +12,7 @@ module Ooor
12
12
  def initialize(session)
13
13
  @session = session
14
14
  end
15
-
15
+
16
16
  def self.define_service(service, methods)
17
17
  methods.each do |meth|
18
18
  self.instance_eval do
@@ -37,17 +37,20 @@ module Ooor
37
37
  else
38
38
  conn = @session.get_client(:json, "#{@session.base_jsonrpc2_url}")
39
39
  response = conn.post do |req|
40
- req.url '/web/session/authenticate'
40
+ req.url '/web/session/authenticate'
41
41
  req.headers['Content-Type'] = 'application/json'
42
42
  req.body = {method: 'call', params: { db: db, login: username, password: password}}.to_json
43
43
  end
44
44
  @session.web_session[:cookie] = response.headers["set-cookie"]
45
+ json_response = JSON.parse(response.body)
46
+ validate_response(json_response)
47
+
45
48
  if response.status == 200
46
49
  sid_part1 = @session.web_session[:cookie].split("sid=")[1]
47
50
  if sid_part1
48
51
  @session.web_session[:sid] = @session.web_session[:cookie].split("sid=")[1].split(";")[0] # NOTE side is required on v7 but not on v8, this enables to sniff if we are on v7
49
52
  end
50
- json_response = JSON.parse(response.body)
53
+
51
54
  @session.web_session[:session_id] = json_response['result']['session_id']
52
55
  user_id = json_response['result']['uid']
53
56
  @session.config[:user_id] = user_id
@@ -58,6 +61,17 @@ module Ooor
58
61
  end
59
62
  end
60
63
  end
64
+
65
+ private
66
+ # Function to validate json response with useful messages
67
+ # Eg: For Database database "<DB NAME>" does not exist errors from open erb.
68
+ def validate_response(json_response)
69
+ error = json_response["error"]
70
+
71
+ if error && (error["data"]["type"] == "server_exception" || error['message'] == "Odoo Server Error")
72
+ raise "#{error["message"]} ------- #{error["data"]["debug"]}"
73
+ end
74
+ end
61
75
  end
62
76
 
63
77
 
@@ -68,7 +82,7 @@ module Ooor
68
82
  @session.logger.info "creating database #{db_name} this may take a while..."
69
83
  process_id = @session.get_client(:xml, @session.base_url + "/db").call("create_database", password, db_name, demo, lang, user_password)
70
84
  sleep(2)
71
- while get_progress(password, process_id)[0] != 1
85
+ while process_id.is_a?(Integer) && get_progress(password, process_id)[0] != 1
72
86
  @session.logger.info "..."
73
87
  sleep(0.5)
74
88
  end
@@ -79,7 +93,7 @@ module Ooor
79
93
 
80
94
  class ObjectService < Service
81
95
  define_service(:object, %w[execute exec_workflow])
82
-
96
+
83
97
  def object_service(service, obj, method, *args)
84
98
  unless @session.config[:user_id]
85
99
  @session.common.login(@session.config[:database], @session.config[:username], @session.config[:password])
@@ -108,7 +122,7 @@ module Ooor
108
122
  end
109
123
 
110
124
  def inject_session_context(service, method, *args)
111
- if service == :object && (i = Ooor.irregular_context_position(method)) && args.size >= i
125
+ if service == :object && (i = Ooor.irregular_context_position(method)) && args.size >= i
112
126
  c = HashWithIndifferentAccess.new(args[i])
113
127
  args[i] = @session.session_context(c)
114
128
  elsif args[-1].is_a? Hash #context
@@ -122,7 +136,7 @@ module Ooor
122
136
  end
123
137
  args
124
138
  end
125
-
139
+
126
140
  end
127
141
 
128
142
 
@@ -14,11 +14,11 @@ module Ooor
14
14
  def get_client(type, url)
15
15
  case type
16
16
  when :json
17
- @json_clients ||= {}
18
- @json_clients[url] ||= JsonClient.new(url, :request => { timeout: config[:rpc_timeout] || 900 })
17
+ Thread.current[:json_clients] ||= {}
18
+ Thread.current[:json_clients][url] ||= JsonClient.new(url, :request => { timeout: config[:rpc_timeout] || 900 })
19
19
  when :xml
20
- @xml_clients ||= {}
21
- @xml_clients[url] ||= XmlRpcClient.new2(url, nil, config[:rpc_timeout] || 900)
20
+ Thread.current[:xml_clients] ||= {}
21
+ Thread.current[:xml_clients][url] ||= XmlRpcClient.new2(url, nil, config[:rpc_timeout] || 900)
22
22
  end
23
23
  end
24
24
 
data/lib/ooor/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ooor
2
2
  MAJOR = 2
3
- MINOR = 1
3
+ MINOR = 2
4
4
  TINY = 0
5
5
  PRE = nil
6
6
 
data/spec/ooor_spec.rb CHANGED
@@ -9,42 +9,44 @@ if ENV["CI"]
9
9
  end
10
10
  require File.dirname(__FILE__) + '/../lib/ooor'
11
11
 
12
+ OOOR_URL = ENV['OOOR_URL'] || 'http://localhost:8069/xmlrpc'
13
+ OOOR_DB_PASSWORD = ENV['OOOR_DB_PASSWORD'] || 'admin'
14
+ OOOR_USERNAME = ENV['OOOR_USERNAME'] || 'admin'
15
+ OOOR_PASSWORD = ENV['OOOR_PASSWORD'] || 'admin'
16
+ OOOR_DATABASE = ENV['OOOR_DATABASE'] || 'ooor_test'
17
+ OOOR_ODOO_VERSION = ENV['VERSION'] || '9.0'
18
+
12
19
  #RSpec executable specification; see http://rspec.info/ for more information.
13
20
  #Run the file with the rspec command from the rspec gem
14
21
  describe Ooor do
15
22
  before(:all) do
16
- @url = 'http://localhost:8069/xmlrpc'
17
- @db_password = 'admin'
18
- @username = 'admin'
19
- @password = 'admin'
20
- @database = 'ooor_test'
21
- @ooor = Ooor.new(:url => @url, :username => @username, :password => @password)
23
+ @ooor = Ooor.new(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD)
22
24
  end
23
25
 
24
26
  it "should keep quiet if no database is mentioned" do
25
- @ooor.models.should be_empty
27
+ expect(@ooor.models).to be_empty
26
28
  end
27
29
 
28
30
  it "should be able to list databases" do
29
- @ooor.db.list.should be_kind_of(Array)
31
+ expect(@ooor.db.list).to be_kind_of(Array)
30
32
  end
31
33
 
32
34
  it "should be able to create a new database with demo data" do
33
- unless @ooor.db.list.index(@database)
34
- @ooor.db.create(@db_password, @database)
35
+ unless @ooor.db.list.index(OOOR_DB_PASSWORD)
36
+ @ooor.db.create(OOOR_DB_PASSWORD, OOOR_DATABASE)
35
37
  end
36
- @ooor.db.list.index(@database).should_not be_nil
38
+ expect(@ooor.db.list.index(OOOR_DATABASE)).not_to be_nil
37
39
  end
38
40
 
39
41
  describe "Configure existing database" do
40
42
  before(:all) do
41
- @ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database)
43
+ @ooor = Ooor.new(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE)
42
44
  end
43
45
 
44
46
  it "should be able to load a profile" do
45
47
  IrModuleModule.install_modules(['sale', 'account_voucher'])
46
48
  @ooor.load_models
47
- @ooor.models.keys.should_not be_empty
49
+ expect(@ooor.models.keys).not_to be_empty
48
50
  end
49
51
 
50
52
  it "should be able to configure the database" do
@@ -59,8 +61,8 @@ describe Ooor do
59
61
 
60
62
  describe "Do operations on configured database" do
61
63
  before(:all) do
62
- @ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database,
63
- :models => ['res.user', 'res.partner', 'product.product', 'sale.order', 'account.invoice', 'product.category', 'ir.cron', 'ir.ui.menu', 'ir.module.module'])
64
+ @ooor = Ooor.new(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE,
65
+ models: ['res.user', 'res.partner', 'product.product', 'sale.order', 'account.invoice', 'product.category', 'ir.cron', 'ir.ui.menu', 'ir.module.module'])
64
66
  end
65
67
 
66
68
  describe "Finders operations" do
@@ -68,42 +70,42 @@ describe Ooor do
68
70
  first_product_id = ProductProduct.search([], 0, 1).first
69
71
  product1 = ProductProduct.find(first_product_id)
70
72
  expect(product1).not_to be_nil
71
- product1.attributes.should be_kind_of(Hash)
73
+ expect(product1.attributes).to be_kind_of(Hash)
72
74
  end
73
75
 
74
76
  it "fetches data given an array of ids" do
75
77
  products = ProductProduct.find([1,2])
76
- products.size.should == 2
78
+ expect(products.size).to eq(2)
77
79
  end
78
80
 
79
81
  it "should fetches data given an implicit array of ids" do
80
82
  products = ProductProduct.find(1, 2)
81
- products.size.should == 2
83
+ expect(products.size).to eq(2)
82
84
  end
83
85
 
84
86
  it "should fetches data even if an id is passed as a string (web usage)" do
85
87
  product = ProductProduct.find("1")
86
- product.should be_kind_of(ProductProduct)
88
+ expect(product).to be_kind_of(ProductProduct)
87
89
  end
88
90
 
89
91
  it "should fetches data even with array containing string" do
90
92
  products = ProductProduct.find(["1", 2])
91
- products.size.should == 2
93
+ expect(products.size).to eq(2)
92
94
  end
93
95
 
94
96
  it "should fetches data even with an implicit array containing string" do
95
97
  products = ProductProduct.find("1", 2)
96
- products.size.should == 2
98
+ expect(products.size).to eq(2)
97
99
  end
98
100
 
99
101
  it "should accept hash domain in find" do
100
102
  products = ProductProduct.find(active: true)
101
- products.should be_kind_of(Array)
103
+ expect(products).to be_kind_of(Array)
102
104
  end
103
105
 
104
106
  it "should accept array domain in find" do
105
107
  products = ProductProduct.find(['active', '=', true])
106
- products.should be_kind_of(Array)
108
+ expect(products).to be_kind_of(Array)
107
109
  end
108
110
 
109
111
  it "fetches last data created last" do
@@ -112,36 +114,36 @@ describe Ooor do
112
114
  end
113
115
 
114
116
  it "should load required models on the fly" do
115
- SaleOrder.find(1).shop_id.should be_kind_of(SaleShop)
117
+ expect(ProductProduct.find(:first).categ_id).to be_kind_of(ProductCategory)
116
118
  end
117
119
 
118
120
  it "should be able to specify the fields to read" do
119
121
  p = ProductProduct.find(1, :fields=>["state", "id"])
120
- p.should_not be_nil
122
+ expect(p).not_to be_nil
121
123
  end
122
124
 
123
125
  it "should be able to find using ir.model.data absolute ids" do
124
126
  p = ResPartner.find('res_partner_1')
125
- p.should_not be_nil
127
+ expect(p).not_to be_nil
126
128
  p = ResPartner.find('base.res_partner_1')#module scoping is optionnal
127
- p.should_not be_nil
129
+ expect(p).not_to be_nil
128
130
  end
129
131
 
130
132
  it "should be able to use OpenERP domains" do
131
133
  partners = ResPartner.find(:all, :domain=>[['supplier', '=', 1],['active','=',1]], :fields=>["id", "name"])
132
- partners.should_not be_empty
134
+ expect(partners).not_to be_empty
133
135
  products = ProductProduct.find(:all, :domain=>[['categ_id','=',1],'|',['name', '=', 'PC1'],['name','=','PC2']])
134
- products.should be_kind_of(Array)
136
+ expect(products).to be_kind_of(Array)
135
137
  end
136
138
 
137
139
  it "should mimic ActiveResource scoping" do
138
140
  partners = ResPartner.find(:all, :params => {:supplier => true})
139
- partners.should_not be_empty
141
+ expect(partners).not_to be_empty
140
142
  end
141
143
 
142
144
  it "should mimic ActiveResource scopinging with first" do
143
145
  partner = ResPartner.find(:first, :params => {:customer => true})
144
- partner.should be_kind_of ResPartner
146
+ expect(partner).to be_kind_of ResPartner
145
147
  end
146
148
 
147
149
  # NOTE: in Ooor 2.1 we don't support this anymore, use session.with_context(context) {} instead
@@ -161,55 +163,57 @@ describe Ooor do
161
163
 
162
164
  it "should support OpenERP search method" do
163
165
  partners = ResPartner.search([['name', 'ilike', 'a']], 0, 2)
164
- partners.should_not be_empty
166
+ expect(partners).not_to be_empty
165
167
  end
166
168
 
167
169
  it "should cast dates properly from OpenERP to Ruby" do
168
170
  o = SaleOrder.find(1)
169
- o.date_order.should be_kind_of(Date)
171
+ expect(o.date_order).to be_kind_of(Date)
170
172
  c = IrCron.find(1)
171
- c.nextcall.should be_kind_of(DateTime)
173
+ expect(c.nextcall).to be_kind_of(DateTime)
172
174
  end
173
175
 
174
176
  it "should not load false values in empty strings (for HTML forms)" do
175
- ResPartner.first.mobile.should be_nil
177
+ expect(ResPartner.first.mobile).to be_nil
176
178
  end
177
179
 
178
180
  it "should map OpenERP types to Rails types" do
179
- (%w[char binary many2one one2many many2many]).each { |t| Ooor::Base.to_rails_type(t).should be_kind_of(Symbol) }
181
+ (%w[char binary many2one one2many many2many]).each { |t| expect(Ooor::Base.to_rails_type(t)).to be_kind_of(Symbol) }
180
182
  end
181
183
 
182
184
  it "should be able to call any Class method" do
183
- ResPartner.name_search('ax', [], 'ilike', {}).should_not be_nil
185
+ expect(ResPartner.name_search('ax', [], 'ilike', {})).not_to be_nil
184
186
  end
185
187
  end
186
188
 
187
189
  describe "Relations reading" do
188
190
  it "should read many2one relations" do
189
191
  o = SaleOrder.find(:first)
190
- o.partner_id.should be_kind_of(ResPartner)
192
+ expect(o.partner_id).to be_kind_of(ResPartner)
191
193
  p = ProductProduct.find(1) #inherited via product template
192
- p.categ_id.should be_kind_of(ProductCategory)
194
+ expect(p.categ_id).to be_kind_of(ProductCategory)
193
195
  end
194
196
 
195
197
  it "should read one2many relations" do
196
198
  o = SaleOrder.find(:first)
197
199
  o.order_line.each do |line|
198
- line.should be_kind_of(SaleOrderLine)
200
+ expect(line).to be_kind_of(SaleOrderLine)
199
201
  end
200
202
  end
201
203
 
204
+ if OOOR_ODOO_VERSION != '9.0'
202
205
  it "should read many2many relations" do
203
206
  s = SaleOrder.find(:first)
204
207
  s.order_policy = 'manual'
205
208
  s.save
206
209
  s.wkf_action('order_confirm')
207
210
  s.wkf_action('manual_invoice')
208
- SaleOrder.find(:first).order_line[1].invoice_lines.should be_kind_of(Array)
211
+ expect(SaleOrder.find(:first).order_line[1].invoice_lines).to be_kind_of(Array)
212
+ end
209
213
  end
210
214
 
211
215
  it "should read polymorphic references" do
212
- IrUiMenu.find(:first, :domain => [['name', '=', 'Customers'], ['parent_id', '!=', false]]).action.should be_kind_of(IrActionsAct_window)
216
+ expect(IrUiMenu.find(:first, :domain => [['name', '=', 'Customers'], ['parent_id', '!=', false]]).action).to be_kind_of(IrActionsAct_window)
213
217
  end
214
218
  end
215
219
 
@@ -217,49 +221,54 @@ describe Ooor do
217
221
  it "should be able to assign a value to an unloaded field" do
218
222
  p = ProductProduct.new
219
223
  p.name = "testProduct1"
220
- p.name.should == "testProduct1"
224
+ expect(p.name).to eq("testProduct1")
221
225
  end
222
226
 
227
+ if OOOR_ODOO_VERSION != '9.0'
223
228
  it "should properly change value when m2o is set" do
224
229
  p = ProductProduct.find(:first)
225
230
  p.categ_id = 7
226
- p.categ_id.id.should == 7
231
+ expect(p.categ_id.id).to eq(7)
232
+ end
227
233
  end
228
234
 
229
235
  it "should be able to create a product" do
230
236
  p = ProductProduct.create(:name => "testProduct1", :categ_id => 1)
231
- ProductProduct.find(p.id).categ_id.id.should == 1
237
+ expect(ProductProduct.find(p.id).categ_id.id).to eq(1)
232
238
  p = ProductProduct.new(:name => "testProduct1")
233
239
  p.categ_id = 1
234
240
  p.save
235
- p.categ_id.id.should == 1
241
+ expect(p.categ_id.id).to eq(1)
236
242
  end
237
243
 
238
244
  it "should support read on new objects" do
239
245
  u = ResUsers.new({name: "joe", login: "joe"})
240
- u.id.should be_nil
241
- u.name.should == "joe"
242
- u.email.should == nil
246
+ expect(u.id).to be_nil
247
+ expect(u.name).to eq("joe")
248
+ expect(u.email).to eq(nil)
243
249
  u.save
244
- u.id.should_not be_nil
245
- u.name.should == "joe"
246
- u.destroy.should be_kind_of(ResUsers)
250
+ expect(u.id).not_to be_nil
251
+ expect(u.name).to eq("joe")
252
+ expect(u.destroy).to be_kind_of(ResUsers)
247
253
  end
248
254
 
249
255
  it "should be able to create an order" do
250
256
  p_id = ResPartner.search([['name', 'ilike', 'Agrolait']])[0]
251
257
  o = SaleOrder.create(partner_id: p_id, partner_invoice_id: p_id, partner_shipping_id: p_id, pricelist_id: 1)
252
- o.id.should be_kind_of(Integer)
258
+ expect(o.id).to be_kind_of(Integer)
253
259
  end
254
260
 
261
+ if OOOR_ODOO_VERSION != '9.0'
255
262
  it "should be able to to create an invoice" do
256
263
  i = AccountInvoice.new(:origin => 'ooor_test')
257
264
  partner_id = ResPartner.search([['name', 'ilike', 'Agrolait']])[0]
258
265
  i.on_change('onchange_partner_id', :partner_id, partner_id, 'out_invoice', partner_id, false, false)
259
266
  i.save
260
- i.id.should be_kind_of(Integer)
267
+ expect(i.id).to be_kind_of(Integer)
268
+ end
261
269
  end
262
270
 
271
+ if OOOR_ODOO_VERSION == '7.0'
263
272
  it "should be able to call on_change" do
264
273
  o = SaleOrder.new
265
274
  partner_id = ResPartner.search([['name', 'ilike', 'Agrolait']])[0]
@@ -271,17 +280,18 @@ describe Ooor do
271
280
  product_uom_qty = 1
272
281
  line.on_change('product_id_change', :product_id, product_id, pricelist_id, product_id, product_uom_qty, false, 1, false, false, o.partner_id.id, 'en_US', true, false, false, false)
273
282
  line.save
274
- SaleOrder.find(o.id).order_line.size.should == 1
283
+ expect(SaleOrder.find(o.id).order_line.size).to eq(1)
284
+ end
275
285
  end
276
286
 
277
287
  it "should use default fields on creation" do
278
288
  p = ProductProduct.new
279
- p.categ_id.should be_kind_of(ProductCategory)
289
+ expect(p.categ_id).to be_kind_of(ProductCategory)
280
290
  end
281
291
 
282
292
  it "should skipped inherited default fields properly, for instance at product variant creation" do
283
293
  #note that we force [] here for the default_get_fields otherwise OpenERP will blows up while trying to write in the product template!
284
- ProductProduct.create({:product_tmpl_id => 25, :code => 'OOOR variant'}, []).should be_kind_of(ProductProduct)
294
+ expect(ProductProduct.create({:product_tmpl_id => 25, :code => 'OOOR variant'}, [])).to be_kind_of(ProductProduct)
285
295
  end
286
296
  end
287
297
 
@@ -294,7 +304,7 @@ describe Ooor do
294
304
 
295
305
  it "should be able to reload resource" do
296
306
  s = SaleOrder.find(:first)
297
- s.reload.should be_kind_of(SaleOrder)
307
+ expect(s.reload).to be_kind_of(SaleOrder)
298
308
  end
299
309
  end
300
310
 
@@ -302,24 +312,28 @@ describe Ooor do
302
312
  it "should be able to assign many2one relations on new" do
303
313
  new_partner_id = ResPartner.search()[0]
304
314
  s = SaleOrder.new(:partner_id => new_partner_id)
305
- s.partner_id.id.should == new_partner_id
315
+ expect(s.partner_id.id).to eq(new_partner_id)
306
316
  end
307
317
 
318
+ if OOOR_ODOO_VERSION != '9.0'
308
319
  it "should be able to do product.taxes_id = [id1, id2]" do
309
320
  p = ProductProduct.find(1)
310
321
  p.taxes_id = AccountTax.search([['type_tax_use','=','sale']])[0..1]
311
322
  p.save
312
- p.taxes_id[0].should be_kind_of(AccountTax)
313
- p.taxes_id[1].should be_kind_of(AccountTax)
323
+ expect(p.taxes_id[0]).to be_kind_of(AccountTax)
324
+ expect(p.taxes_id[1]).to be_kind_of(AccountTax)
325
+ end
314
326
  end
315
327
 
328
+ if OOOR_ODOO_VERSION == '7.0'
316
329
  it "should be able to create one2many relations on the fly" do
317
330
  so = SaleOrder.new
318
331
  partner_id = ResPartner.search([['name', 'ilike', 'Agrolait']])[0]
319
332
  so.on_change('onchange_partner_id', :partner_id, partner_id, partner_id) #auto-complete the address and other data based on the partner
320
333
  so.order_line = [SaleOrderLine.new(:name => 'sl1', :product_id => 1, :price_unit => 21, :product_uom => 1), SaleOrderLine.new(:name => 'sl2', :product_id => 1, :price_unit => 21, :product_uom => 1)] #create one order line
321
334
  so.save
322
- so.amount_total.should == 42.0
335
+ expect(so.amount_total).to eq(42.0)
336
+ end
323
337
  end
324
338
 
325
339
  it "should be able to assign a polymorphic relation" do
@@ -330,24 +344,25 @@ describe Ooor do
330
344
  describe "Rails associations methods" do
331
345
  it "should read m2o id with an extra _id suffix" do
332
346
  p = ProductProduct.find(1)
333
- p.categ_id_id.should be_kind_of(Integer)
347
+ expect(p.categ_id_id).to be_kind_of(Integer)
334
348
  end
335
349
 
336
350
  it "should read o2m with an extra _ids suffix" do
337
351
  so = SaleOrder.find :first
338
- so.order_line_ids.should be_kind_of(Array)
352
+ expect(so.order_line_ids).to be_kind_of(Array)
339
353
  end
340
354
 
341
355
  it "should read m2m with an extra _ids suffix" do
342
356
  p = ProductProduct.find(1)
343
- p.taxes_id_ids.should be_kind_of(Array)
357
+ expect(p.taxes_id_ids).to be_kind_of(Array)
344
358
  end
345
359
 
346
360
  it "should support Rails nested attributes methods" do
347
361
  so = SaleOrder.find :first
348
- so.respond_to?(:order_line_attributes=).should == true
362
+ expect(so.respond_to?(:order_line_attributes=)).to eq(true)
349
363
  end
350
364
 
365
+ if OOOR_ODOO_VERSION == '7.0'
351
366
  it "should support CRUD on o2m via nested attributes" do
352
367
  p = ProductProduct.create(name:'Ooor product with packages')
353
368
  p.packaging_attributes = {'1' => {name: 'pack1'}, '2' => {name: 'pack2'}}
@@ -355,39 +370,44 @@ describe Ooor do
355
370
  p = ProductProduct.find p.id
356
371
  pack1 = p.packaging[0]
357
372
  pack2 = p.packaging[1]
358
- pack2.name.index('pack').should == 0
373
+ expect(pack2.name.index('pack')).to eq(0)
359
374
  p.packaging_attributes = {'1' => {name: 'pack1', '_destroy'=> true, id: pack1.id}, '2' => {name: 'pack2_modified', id: pack2.id}}
360
375
  p.save
361
- p.packaging.size.should == 1
362
- p.packaging[0].name.should == 'pack2_modified'
376
+ expect(p.packaging.size).to eq(1)
377
+ expect(p.packaging[0].name).to eq('pack2_modified')
378
+ end
363
379
  end
364
380
 
365
381
  it "should be able to call build upon a o2m association" do
366
382
  so = SaleOrder.find :first
367
- so.order_line.build().should be_kind_of(SaleOrderLine)
383
+ expect(so.order_line.build()).to be_kind_of(SaleOrderLine)
368
384
  end
369
385
 
386
+ if OOOR_ODOO_VERSION != '9.0'
370
387
  it "should recast string m2o string id to an integer (it happens in forms)" do
371
388
  uom_id = @ooor.const_get('product.uom').search()[0]
372
389
  p = ProductProduct.new(name: "z recast id", uom_id: uom_id.to_s)
373
390
  p.save
374
- p.uom_id.id.should == uom_id
391
+ expect(p.uom_id.id).to eq(uom_id)
392
+ end
375
393
  end
376
394
 
377
395
  it "should recast string m2m string ids to an array of integer (it happens in forms)" do
378
396
  categ_ids = @ooor.const_get('res.partner.category').search()[0..1]
379
397
  p = ResPartner.new(name: "z recast ids", category_id: categ_ids.join(','))
380
398
  p.save
381
- p.category_id.map{|c| c.id}.should == categ_ids
399
+ expect(p.category_id.map{|c| c.id}).to eq(categ_ids)
382
400
  end
383
401
  end
384
402
 
385
403
  describe "Fields validations" do
404
+ if OOOR_ODOO_VERSION == '7.0'
386
405
  it "should point to invalid fields" do
387
406
  p = ProductProduct.find :first
388
407
  p.ean13 = 'invalid_ean'
389
- p.save.should == false
390
- p.errors.messages[:ean13].should_not be_nil
408
+ expect(p.save).to eq(false)
409
+ expect(p.errors.messages[:ean13]).not_to be_nil
410
+ end
391
411
  end
392
412
 
393
413
  it "should list all available fields when you call an invalid field" do
@@ -409,10 +429,11 @@ describe Ooor do
409
429
  with_ooor_session username: 'admin', password: 'admin' do |session|
410
430
  menu = session['ir.ui.menu'].first
411
431
  menu.save
412
- probe.should == menu.name
432
+ expect(probe).to eq(menu.name)
413
433
  end
414
434
  end
415
435
 
436
+ if OOOR_ODOO_VERSION == '7.0'
416
437
  it "should call customized before_save callback on nested o2m" do
417
438
  with_ooor_session({username: 'admin', password: 'admin'}, 'noshare1') do |session|
418
439
  # we purposely make reflections happen to ensure they won't be reused in next session
@@ -428,71 +449,81 @@ describe Ooor do
428
449
 
429
450
  with_ooor_session({username: 'admin', password: 'admin'}, 'noshare2') do |session|
430
451
  p = session['product.product'].create name: 'nested callback test', packaging_attributes: {'1' => {name: 'pack'}, '2' => {name: 'pack'}}
431
- probe.should == 'pack'
452
+ expect(probe).to eq('pack')
432
453
  end
433
454
  end
455
+ end
434
456
 
435
457
  end
436
458
 
437
459
  describe "ARel emulation" do
438
460
  it "should have an 'all' method" do
439
- ResUsers.all.should be_kind_of(Array)
461
+ expect(ResUsers.all).to be_kind_of(Array)
440
462
  end
441
463
 
442
464
  it "should have a 'first' method" do
443
- ResUsers.first.id.should == 1
465
+ expect(ResUsers.first.id).to eq(1)
444
466
  end
445
467
 
446
468
  it "should have a 'last' method" do
447
- ResUsers.last.id.should == ResUsers.find(:last).id
469
+ expect(ResUsers.last.id).to eq(ResUsers.find(:last).id)
448
470
  end
449
471
 
450
472
  it "should be ready for Kaminari pagination via ARel scoping" do
451
473
  num = 2
452
474
  default_per_page = 5
453
475
  collection = ProductProduct.where(active: true).limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1)).order("categ_id")
454
- collection.all(fields:['name']).should be_kind_of(Array)
455
- collection.all.size.should == 5
476
+ expect(collection.all(fields:['name'])).to be_kind_of(Array)
477
+ expect(collection.all.size).to eq(5)
456
478
  end
457
479
 
480
+ if OOOR_ODOO_VERSION != '9.0'
458
481
  it "should support name_search in ARel (used in association widgets with Ooorest)" do
459
- Ooor.default_session.const_get('product.category').all(name_search: 'Com')[0].name.should == "All products / Saleable / Components"
482
+ if OOOR_ODOO_VERSION == '7.0'
483
+ expected = "All products / Saleable / Components"
484
+ else
485
+ expected = "All / Saleable / Components"
486
+ end
487
+ expect(Ooor.default_session.const_get('product.category').all(name_search: 'Com')[0].name).to eq(expected)
488
+ end
460
489
  end
461
490
 
462
491
  it "should be possible to invoke batch methods on relations" do
463
- Ooor.default_session.const_get('product.product').where(type: 'service').write(type: 'service').should == true
492
+ expect(Ooor.default_session.const_get('product.product').where(type: 'service').write(type: 'service')).to eq(true)
464
493
  end
465
494
 
466
495
  it "should forward Array methods to the Array" do
467
- Ooor.default_session.const_get('product.product').where(type: 'service').size.should be_kind_of(Integer)
496
+ expect(Ooor.default_session.const_get('product.product').where(type: 'service').size).to be_kind_of(Integer)
468
497
  end
469
498
 
470
499
  it "should support reloading relation" do
471
- Ooor.default_session.const_get('product.product').where(type: 'service').reload.all.should be_kind_of(Array)
500
+ expect(Ooor.default_session.const_get('product.product').where(type: 'service').reload.all).to be_kind_of(Array)
472
501
  end
473
502
  end
474
503
 
475
504
  describe "report support" do
476
- it "should print reports" do
505
+ if OOOR_ODOO_VERSION == '7.0'
506
+ it "should print reports" do # TODO make work in v8
477
507
  base_id = IrModuleModule.search(name:'base')[0]
478
- IrModuleModule.get_report_data("ir.module.reference", [base_id], 'pdf', {}).should be_kind_of(Array)
508
+ expect(IrModuleModule.get_report_data("ir.module.reference", [base_id], 'pdf', {})).to be_kind_of(Array)
509
+ end
479
510
  end
480
511
  end
481
512
 
482
513
  describe "wizard management" do
514
+ if OOOR_ODOO_VERSION != '9.0'
483
515
  it "should be possible to pay an invoice in one step" do
484
516
  inv = AccountInvoice.find(:first).copy() # creates a draft invoice
485
- inv.state.should == "draft"
517
+ expect(inv.state).to eq("draft")
486
518
  inv.wkf_action('invoice_open')
487
- inv.state.should == "open"
519
+ expect(inv.state).to eq("open")
488
520
  voucher = @ooor.const_get('account.voucher').new({:amount=>inv.amount_total, :type=>"receipt", :partner_id => inv.partner_id.id}, {"default_amount"=>inv.amount_total, "invoice_id"=>inv.id})
489
521
  voucher.on_change("onchange_partner_id", [], :partner_id, inv.partner_id.id, @ooor.const_get('account.journal').find('account.bank_journal').id, 0.0, 1, 'receipt', false)
490
522
  voucher.save
491
- # voucher.wkf_action 'proforma_voucher'
492
-
493
- # inv.reload
523
+ end
494
524
  end
495
525
 
526
+ if OOOR_ODOO_VERSION != '9.0'
496
527
  it "should be possible to call resource actions and workflow actions" do
497
528
  s = SaleOrder.find(:first).copy()
498
529
  s.wkf_action('order_confirm')
@@ -503,7 +534,8 @@ describe Ooor do
503
534
  i.wkf_action('invoice_open')
504
535
  i.wkf_action('invoice_cancel')
505
536
  i.action_cancel_draft
506
- s.reload.state.should == "invoice_except"
537
+ expect(s.reload.state).to eq("invoice_except")
538
+ end
507
539
  end
508
540
  end
509
541
 
@@ -526,7 +558,7 @@ describe Ooor do
526
558
 
527
559
  describe "Object context abilities" do
528
560
  before(:all) do
529
- @ooor = Ooor.new(:url => @url, :database => @database, :username => @username, :password => @password)
561
+ @ooor = Ooor.new(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE)
530
562
  end
531
563
 
532
564
  it "should support context when instanciating collections" do
@@ -543,126 +575,130 @@ describe Ooor do
543
575
  include Ooor
544
576
 
545
577
  it "should support ActiveModel::Naming" do
546
- with_ooor_session(:url => @url, :database => @database, :username => @username, :password => @password) do |session|
547
- session['product.product'].name.should == "ProductProduct"
548
- session['product.product'].model_name.route_key.should == "product-product"
549
- session['product.product'].model_name.param_key.should == "product_product" #TODO add more expectations
578
+ with_ooor_session(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE) do |session|
579
+ expect(session['product.product'].name).to eq("ProductProduct")
580
+ expect(session['product.product'].model_name.route_key).to eq("product-product")
581
+ expect(session['product.product'].model_name.param_key).to eq("product_product") #TODO add more expectations
550
582
  end
551
583
  end
552
584
 
553
585
  it "should support model aliases" do
554
586
  Ooor.session_handler.reset!() # alias isn't part of the connection spec, we don't want connectio reuse here
555
- with_ooor_session(:url => @url, :database => @database, :username => @username, :password => @password, :aliases => {en_US: {products: 'product.product'}}, :param_keys => {'product.product' => 'name'}) do |session|
556
- session['products'].search().should be_kind_of(Array)
557
- session['product.product'].alias.should == 'products'
587
+ with_ooor_session(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE, :aliases => {en_US: {products: 'product.product'}}, :param_keys => {'product.product' => 'name'}) do |session|
588
+ expect(session['products'].search()).to be_kind_of(Array)
589
+ expect(session['product.product'].alias).to eq('products')
558
590
  end
559
591
  end
560
592
 
561
593
  it "should have a to_param method" do
562
594
  Ooor.session_handler.reset!() # alias isn't part of the connection spec, we don't want connectio reuse here
563
- with_ooor_session(:url => @url, :database => @database, :username => @username, :password => @password, :aliases => {en_US: {products: 'product.product'}}, :param_keys => {'product.product' => 'name'}) do |session|
564
- session['product.product'].find(:first).to_param.should be_kind_of(String)
595
+ with_ooor_session(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE, :aliases => {en_US: {products: 'product.product'}}, :param_keys => {'product.product' => 'name'}) do |session|
596
+ expect(session['product.product'].find(:first).to_param).to be_kind_of(String)
565
597
  end
566
598
  end
567
599
 
600
+ if OOOR_ODOO_VERSION != '9.0' # TODO make it work on 9
568
601
  it "should find by permalink" do
569
602
  Ooor.session_handler.reset!() # alias isn't part of the connection spec, we don't want connection reuse here
570
- with_ooor_session(:url => @url, :database => @database, :username => @username, :password => @password, :aliases => {en_US: {products: 'product.product'}}, :param_keys => {'product.product' => 'name'}) do |session|
603
+ with_ooor_session(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE, :aliases => {en_US: {products: 'product.product'}}, :param_keys => {'product.product' => 'name'}) do |session|
571
604
  lang = Ooor::Locale.to_erp_locale('en')
572
- session['products'].find_by_permalink('Service', context: {'lang' => lang}, fields: ['name']).should be_kind_of(Ooor::Base)
605
+ expect(session['products'].find_by_permalink('Service', context: {'lang' => lang}, fields: ['name'])).to be_kind_of(Ooor::Base)
573
606
  end
574
607
  end
608
+ end
575
609
  end
576
610
 
577
611
  describe "Ative-Record like Reflections" do
578
612
  before(:all) do
579
- @ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :models => ['product.product', 'product.category'], :reload => true)
613
+ @ooor = Ooor.new(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE, :models => ['product.product', 'product.category'], :reload => true)
580
614
  end
581
615
 
582
616
  it "should test correct class attributes of ActiveRecord Reflection" do
583
617
  object = Ooor::Reflection::AssociationReflection.new(:test, :people, {}, nil)
584
- object.name.should == :people
585
- object.macro.should == :test
586
- object.options.should == {}
618
+ expect(object.name).to eq(:people)
619
+ expect(object.macro).to eq(:test)
620
+ expect(object.options).to eq({})
587
621
  end
588
622
 
589
623
  it "should test correct class name matching with class name" do
590
624
  object = Ooor::Reflection::AssociationReflection.new(:test, 'product_product', {class_name: 'product.product'}, nil)
591
625
  object.session = @ooor
592
- object.klass.should == ProductProduct
626
+ expect(object.klass).to eq(ProductProduct)
593
627
  end
594
628
 
595
629
  it "should reflect on m2o association (used in simple_form, cocoon...)" do
596
630
  reflection = ProductProduct.reflect_on_association(:categ_id)
597
- reflection.should be_kind_of(Ooor::Reflection::AssociationReflection)
598
- reflection.klass.should == ProductCategory
631
+ expect(reflection).to be_kind_of(Ooor::Reflection::AssociationReflection)
632
+ expect(reflection.klass).to eq(ProductCategory)
599
633
  end
600
634
 
635
+ if OOOR_ODOO_VERSION == '7.0'
601
636
  it "should reflect on o2m association (used in simple_form, cocoon...)" do
602
637
  reflection = ProductProduct.reflect_on_association(:packaging)
603
- reflection.should be_kind_of(Ooor::Reflection::AssociationReflection)
638
+ expect(reflection).to be_kind_of(Ooor::Reflection::AssociationReflection)
604
639
  reflection.klass.openerp_model == 'product.packaging'
605
640
  end
641
+ end
606
642
 
607
643
  it "should reflect on m2m association (used in simple_form, cocoon...)" do
608
644
  reflection = ResPartner.reflect_on_association(:category_id)
609
- reflection.should be_kind_of(Ooor::Reflection::AssociationReflection)
610
- reflection.klass.should == ResPartnerCategory
645
+ expect(reflection).to be_kind_of(Ooor::Reflection::AssociationReflection)
646
+ expect(reflection.klass).to eq(ResPartnerCategory)
611
647
  end
612
648
 
613
649
  it "should support column_for_attribute (used by simple_form)" do
614
- @ooor.const_get('ir.cron').find(:first).column_for_attribute('name')[:type].should == :string
650
+ expect(@ooor.const_get('ir.cron').find(:first).column_for_attribute('name')[:type]).to eq(:string)
615
651
  end
616
652
  end
617
653
 
618
654
  describe "Multi-instance and class name scoping" do
619
655
  before(:all) do
620
- @ooor1 = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :scope_prefix => 'OE1', :models => ['res.partner', 'product.product'], :reload => true)
621
- @ooor2 = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :scope_prefix => 'OE2', :models => ['res.partner', 'product.product'], :reload => true)
656
+ @ooor1 = Ooor.new(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE, :scope_prefix => 'OE1', :models => ['res.partner', 'product.product'], :reload => true)
657
+ @ooor2 = Ooor.new(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE, :scope_prefix => 'OE2', :models => ['res.partner', 'product.product'], :reload => true)
622
658
  end
623
659
 
624
660
  it "should still be possible to find a ressource using an absolute id" do
625
- OE1::ResPartner.find('res_partner_1').should be_kind_of(OE1::ResPartner)
661
+ expect(OE1::ResPartner.find('res_partner_1')).to be_kind_of(OE1::ResPartner)
626
662
  end
627
663
 
628
664
  it "should be able to read in one instance and write in an other" do
629
665
  p1 = OE1::ProductProduct.find(1)
630
666
  p2 = OE2::ProductProduct.create(:name => p1.name, :categ_id => p1.categ_id.id)
631
- p2.should be_kind_of(OE2::ProductProduct)
667
+ expect(p2).to be_kind_of(OE2::ProductProduct)
632
668
  end
633
669
  end
634
670
 
635
671
  describe "Multi-sessions mode" do
636
672
  include Ooor
637
673
  it "should allow with_session" do
638
- with_ooor_session(:url => @url, :username => @username, :password => @password, :database => @database) do |session|
639
- session['res.users'].search().should be_kind_of(Array)
674
+ with_ooor_session(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE) do |session|
675
+ expect(session['res.users'].search()).to be_kind_of(Array)
640
676
  new_user = session['res.users'].create(name: 'User created by OOOR as admin', login: 'ooor1')
641
677
  new_user.destroy
642
678
  end
643
679
 
644
- with_ooor_session(:url => @url, :username => 'demo', :password => 'demo', :database => @database) do |session|
680
+ with_ooor_session(url: OOOR_URL, username: 'demo', password: 'demo', database: OOOR_DATABASE) do |session|
645
681
  h = session['res.users'].read([1], ["password"])
646
- h[0]['password'].should == "********"
682
+ expect(h[0]['password']).to eq("********")
647
683
  end
648
684
 
649
- with_ooor_default_session(:url => @url, :username => @username, :password => @password, :database => @database) do |session|
650
- session['res.users'].search().should be_kind_of(Array)
685
+ with_ooor_default_session(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE) do |session|
686
+ expect(session['res.users'].search()).to be_kind_of(Array)
651
687
  end
652
688
  end
653
689
 
654
690
  it "should recover from expired sessions" do
655
- with_ooor_session(:url => @url, :username => @username, :password => @password, :database => @database) do |session|
691
+ with_ooor_session(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE) do |session|
656
692
  user_obj = session['res.users']
657
- user_obj.search().should be_kind_of(Array)
693
+ expect(user_obj.search()).to be_kind_of(Array)
658
694
  session.web_session[:session_id] = 'invalid'
659
- user_obj.search().should be_kind_of(Array)
695
+ expect(user_obj.search()).to be_kind_of(Array)
660
696
  end
661
697
  end
662
698
 
663
699
  it "should raise AccessDenied/UnAuthorizedError errors" do
664
700
  expect do
665
- with_ooor_session(:url => @url, :username => 'demo', :password => 'demo', :database => @database) do |session|
701
+ with_ooor_session(url: OOOR_URL, username: 'demo', password: 'demo', database: OOOR_DATABASE) do |session|
666
702
  session['ir.ui.menu'].first.save
667
703
  end
668
704
  end.to raise_error(Ooor::UnAuthorizedError)
@@ -670,13 +706,13 @@ describe Ooor do
670
706
 
671
707
  it "should assign a secure web session_id to a new web session" do
672
708
  session = Ooor.session_handler.retrieve_session({}, nil, {})
673
- session.id.should be_kind_of String
674
- session.id.size.should == 32
709
+ expect(session.id).to be_kind_of String
710
+ expect(session.id.size).to eq(32)
675
711
  end
676
712
 
677
713
  it "should keep existing web session_id" do
678
714
  session = Ooor.session_handler.retrieve_session({}, "12345678912345", {})
679
- session.id.should == "12345678912345"
715
+ expect(session.id).to eq("12345678912345")
680
716
  end
681
717
 
682
718
  it "should reuse the same session and proxies with session with same spec" do
@@ -684,16 +720,16 @@ describe Ooor do
684
720
  obj2 = 2
685
721
  s1 = 1
686
722
  s2 = 2
687
- with_ooor_session(:url => @url, :username => 'demo', :password => 'demo', :database => @database) do |session1|
723
+ with_ooor_session(url: OOOR_URL, username: 'demo', password: 'demo', database: OOOR_DATABASE) do |session1|
688
724
  s1 = session1
689
725
  obj1 = session1['ir.ui.menu']
690
726
  end
691
- with_ooor_session(:url => @url, :username => 'demo', :password => 'demo', :database => @database) do |session2|
727
+ with_ooor_session(url: OOOR_URL, username: 'demo', password: 'demo', database: OOOR_DATABASE) do |session2|
692
728
  s2 = session2
693
729
  obj2 = session2['ir.ui.menu']
694
730
  end
695
- s1.object_id.should == s2.object_id
696
- obj1.object_id.should == obj2.object_id
731
+ expect(s1.object_id).to eq(s2.object_id)
732
+ expect(obj1.object_id).to eq(obj2.object_id)
697
733
  end
698
734
 
699
735
  it "should not reuse the same session and proxies with session with different spec" do
@@ -701,18 +737,18 @@ describe Ooor do
701
737
  obj2 = 2
702
738
  s1 = 1
703
739
  s2 = 2
704
- with_ooor_session(:url => @url, :username => 'admin', :password => 'admin', :database => @database) do |session1|
740
+ with_ooor_session(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE) do |session1|
705
741
  s1 = session1
706
742
  obj1 = session1['ir.ui.menu']
707
743
  end
708
744
 
709
- with_ooor_session(:url => @url, :username => 'demo', :password => 'demo', :database => @database) do |session2|
745
+ with_ooor_session(url: OOOR_URL, username: 'demo', password: 'demo', database: OOOR_DATABASE) do |session2|
710
746
  s2 = session2
711
747
  obj2 = session2['ir.ui.menu']
712
748
  end
713
749
 
714
- s1.object_id.should_not == s2.object_id
715
- obj1.object_id.should_not == obj2.object_id
750
+ expect(s1.object_id).not_to eq(s2.object_id)
751
+ expect(obj1.object_id).not_to eq(obj2.object_id)
716
752
  end
717
753
 
718
754
  it "when using different web sessions, it should still share model schemas" do
@@ -720,18 +756,18 @@ describe Ooor do
720
756
  obj2 = 2
721
757
  s1 = 1
722
758
  s2 = 2
723
- with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 111) do |session1|
759
+ with_ooor_session({url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE}, 111) do |session1|
724
760
  s1 = session1
725
761
  obj1 = Ooor.model_registry.get_template(session1.config, 'ir.ui.menu')
726
762
  end
727
763
 
728
- with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 123) do |session2|
764
+ with_ooor_session({url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE}, 123) do |session2|
729
765
  s2 = session2
730
766
  obj2 = Ooor.model_registry.get_template(session2.config, 'ir.ui.menu')
731
767
  end
732
768
 
733
- s1.object_id.should_not == s2.object_id
734
- obj1.should == obj2 unless ActiveModel::VERSION::STRING.start_with? "3.2" #for some reason this doesn't work with Rails 3.2
769
+ expect(s1.object_id).not_to eq(s2.object_id)
770
+ expect(obj1).to eq(obj2) unless ActiveModel::VERSION::STRING.start_with? "3.2" #for some reason this doesn't work with Rails 3.2
735
771
  end
736
772
 
737
773
 
@@ -739,30 +775,30 @@ describe Ooor do
739
775
  s1 = 1
740
776
  s2 = 2
741
777
 
742
- with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 123) do |session1|
778
+ with_ooor_session({url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE}, 123) do |session1|
743
779
  s1 = session1
744
780
  end
745
781
 
746
- with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 123) do |session1|
782
+ with_ooor_session({url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE}, 123) do |session1|
747
783
  s2 = session1
748
784
  end
749
785
 
750
- s1.object_id.should == s2.object_id
786
+ expect(s1.object_id).to eq(s2.object_id)
751
787
  end
752
788
 
753
789
  it "should not use the same session when session spec matches but session_id is different (web)" do
754
790
  s1 = 1
755
791
  s2 = 2
756
792
 
757
- with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 111) do |session1|
793
+ with_ooor_session({url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE}, 111) do |session1|
758
794
  s1 = session1
759
795
  end
760
796
 
761
- with_ooor_session({:url => @url, :username => 'admin', :password => 'admin', :database => @database}, 123) do |session1|
797
+ with_ooor_session({url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE}, 123) do |session1|
762
798
  s2 = session1
763
799
  end
764
800
 
765
- s1.object_id.should_not == s2.object_id
801
+ expect(s1.object_id).not_to eq(s2.object_id)
766
802
  end
767
803
 
768
804
  end
@@ -770,7 +806,7 @@ describe Ooor do
770
806
 
771
807
  describe "Multi-format serialization" do
772
808
  before(:all) do
773
- @ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database)
809
+ @ooor = Ooor.new(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE)
774
810
  end
775
811
 
776
812
  it "should serialize in json" do
@@ -783,7 +819,7 @@ describe Ooor do
783
819
 
784
820
  describe "Ruby OpenERP extensions" do
785
821
  before(:all) do
786
- @ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :helper_paths => [File.dirname(__FILE__) + '/helpers/*'], :reload => true)
822
+ @ooor = Ooor.new(url: OOOR_URL, username: OOOR_USERNAME, password: OOOR_PASSWORD, database: OOOR_DATABASE, :helper_paths => [File.dirname(__FILE__) + '/helpers/*'], :reload => true)
787
823
  end
788
824
 
789
825
  it "should have default core helpers loaded" do
@@ -792,9 +828,9 @@ describe Ooor do
792
828
  end
793
829
 
794
830
  it "should load custom helper paths" do
795
- IrModuleModule.say_hello.should == "Hello"
831
+ expect(IrModuleModule.say_hello).to eq("Hello")
796
832
  mod = IrModuleModule.find(:first, :domain=>['name', '=', 'sale'])
797
- mod.say_name.should == "sale"
833
+ expect(mod.say_name).to eq("sale")
798
834
  end
799
835
 
800
836
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raphael Valyi - www.akretion.com
@@ -104,10 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.4.5.1
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: OOOR - OpenObject On Ruby
111
111
  test_files:
112
- - spec/ooor_spec.rb
113
112
  - spec/helpers/test_helper.rb
113
+ - spec/ooor_spec.rb