cucumber-openerpscenario 0.1.6 → 0.1.7
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/cucumber-openerp.gemspec +1 -1
- data/cucumber-openerpscenario-0.1.6.gem +0 -0
- data/lib/cucumber/openerp/dsl.rb +10 -2
- data/lib/cucumber/openerp/dsl.rb.~1~ +122 -0
- metadata +3 -1
data/cucumber-openerp.gemspec
CHANGED
Binary file
|
data/lib/cucumber/openerp/dsl.rb
CHANGED
@@ -61,7 +61,7 @@ def manage_item_table(item, table)
|
|
61
61
|
fields.merge! item.class.many2one_associations
|
62
62
|
fields.merge! item.class.one2many_associations
|
63
63
|
fields.merge! item.class.many2many_associations
|
64
|
-
|
64
|
+
|
65
65
|
table.hashes.each do |dict|
|
66
66
|
if fields[dict['name']]
|
67
67
|
rel_item = _manage_col_search(fields[dict['name']], dict['value'])
|
@@ -73,10 +73,18 @@ def manage_item_table(item, table)
|
|
73
73
|
value = Integer(value)
|
74
74
|
elsif v_type == 'float'
|
75
75
|
value = Float(value)
|
76
|
+
elsif v_type == 'boolean'
|
77
|
+
if [nil, 0, false, ''].include? value
|
78
|
+
value = false
|
79
|
+
end
|
80
|
+
elsif ['date', 'datetime'].include? v_type
|
81
|
+
if value.include? "%"
|
82
|
+
value = Time.new().strftime(value)
|
83
|
+
end
|
76
84
|
end
|
77
85
|
eval "item.#{dict['name']} = value"
|
78
86
|
end
|
79
|
-
end
|
87
|
+
end
|
80
88
|
end
|
81
89
|
|
82
90
|
Given /^I (create|need|should have|find|find or create) (a|all|last) "([^"]*)" with (.*)$/ do |action, qty, model, args|
|
@@ -0,0 +1,122 @@
|
|
1
|
+
def prepare_args(args)
|
2
|
+
mixed = args.strip.split('and')
|
3
|
+
attrs = []
|
4
|
+
arguments = []
|
5
|
+
mixed.each do |set|
|
6
|
+
tmp = set.split(':')
|
7
|
+
attrs.push(tmp[0].strip)
|
8
|
+
arguments.push(tmp[1].strip)
|
9
|
+
end
|
10
|
+
attrs_string = attrs.join('_and_')
|
11
|
+
return attrs_string, arguments
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_items(action, qty, model, args)
|
15
|
+
@found_items = nil
|
16
|
+
@found_item = nil
|
17
|
+
oclass = Object.const_get(model.split('.').collect {|s| s.capitalize}.join)
|
18
|
+
unique_mode = ['create', 'need', 'find or create']
|
19
|
+
if qty == 'all'
|
20
|
+
if unique_mode.include? action
|
21
|
+
raise "#{unique_mode.inspect} does not allows 'all' keyword"
|
22
|
+
end
|
23
|
+
qty = 'all_'
|
24
|
+
else
|
25
|
+
qty = ''
|
26
|
+
end
|
27
|
+
command_map = {'create' => 'new', 'need' => 'find_or_initialize_by_', 'shoud_have' => "find_#{qty}by_", 'find' => "find_#{qty}by_", 'find or create' => 'find_or_initialize_by_'}
|
28
|
+
comm_ext, arguments = prepare_args(args)
|
29
|
+
arguments.push({:fields =>['id']})
|
30
|
+
if command_map[action] == 'create'
|
31
|
+
if oclass.send(('find_by_'+comm_ext).to_sym, *arguments)
|
32
|
+
raise "Error object allerady exist if this is not the wished behavior please use need keyword"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
res = oclass.send((command_map[action]+comm_ext).to_sym, *arguments) # I know in case or create we do 2 search but as there should be nul it cost almost nothing
|
36
|
+
if @found_items.is_a? Array
|
37
|
+
@found_items = res
|
38
|
+
else
|
39
|
+
@found_item = res
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def _manage_col_search(field_def, value)
|
44
|
+
oclass = Object.const_get(field_def['relation'].split('.').collect {|s| s.capitalize}.join) # TODO use Scenario helper
|
45
|
+
oid = nil
|
46
|
+
if value.start_with? 'by '
|
47
|
+
comm_ext, arguments = prepare_args(value.gsub('by ', ''))
|
48
|
+
arguments.push({'fields'=>['id']})
|
49
|
+
oid = oclass.send(('find_by_'+comm_ext).to_sym, *arguments)
|
50
|
+
else
|
51
|
+
eval "oid = oclass.#{value}"
|
52
|
+
end
|
53
|
+
unless oid
|
54
|
+
raise "Can not find #{value}"
|
55
|
+
end
|
56
|
+
return oid
|
57
|
+
end
|
58
|
+
|
59
|
+
def manage_item_table(item, table)
|
60
|
+
fields = {}
|
61
|
+
fields.merge! item.class.many2one_associations
|
62
|
+
fields.merge! item.class.one2many_associations
|
63
|
+
fields.merge! item.class.many2many_associations
|
64
|
+
|
65
|
+
table.hashes.each do |dict|
|
66
|
+
if fields[dict['name']]
|
67
|
+
rel_item = _manage_col_search(fields[dict['name']], dict['value'])
|
68
|
+
eval "item.#{dict['name']} = rel_item.id"
|
69
|
+
else
|
70
|
+
value = dict['value']
|
71
|
+
v_type = item.class.fields.fetch(dict['name'],{}).fetch('type', nil)
|
72
|
+
if v_type == 'integer'
|
73
|
+
value = Integer(value)
|
74
|
+
elsif v_type == 'float'
|
75
|
+
value = Float(value)
|
76
|
+
elsif v_type == 'boolean'
|
77
|
+
if [nil, 0, false, ''].include? value
|
78
|
+
value = false
|
79
|
+
end
|
80
|
+
elsif ['date', 'datetime'].include? v_type
|
81
|
+
if value.include? "%"
|
82
|
+
value = Time.new().strftime(value)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
eval "item.#{dict['name']} = value"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
Given /^I (create|need|should have|find|find or create) (a|all|last) "([^"]*)" with (.*)$/ do |action, qty, model, args|
|
91
|
+
get_items(action, qty, model, args)
|
92
|
+
end
|
93
|
+
|
94
|
+
Given /^(having:|prepared with:)$/ do |mode, table|
|
95
|
+
@found_item.should_not be_nil,
|
96
|
+
"No item to set attribute found"
|
97
|
+
manage_item_table(@found_item, table)
|
98
|
+
unless mode == 'prepared with:'
|
99
|
+
@found_item.save
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
Given /^having$/ do |table|
|
104
|
+
$utils.log.warn "Deprecated sentence, please use this one : \"having:\""
|
105
|
+
step "having:", table
|
106
|
+
end
|
107
|
+
|
108
|
+
Given /^I save$/ do
|
109
|
+
@found_item.should_not be_nil,
|
110
|
+
"No item to set attribute found"
|
111
|
+
@found_item.save
|
112
|
+
end
|
113
|
+
|
114
|
+
Then /^I remove the Log fields$/ do
|
115
|
+
# weird hack
|
116
|
+
# for some objects, a bug forbid to save a resource
|
117
|
+
# and we have to delete the log columns before save them
|
118
|
+
@found_item.associations.delete('write_uid')
|
119
|
+
@found_item.associations.delete('create_uid')
|
120
|
+
@found_item.attributes.delete('write_date')
|
121
|
+
@found_item.attributes.delete('create_date')
|
122
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cucumber-openerpscenario
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nicolas Bessi - Camptocamp
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- README.txt
|
83
83
|
- bin/cucumber-openerp
|
84
84
|
- cucumber-openerp.gemspec
|
85
|
+
- cucumber-openerpscenario-0.1.6.gem
|
85
86
|
- lib/.DS_Store
|
86
87
|
- lib/cucumber/.DS_Store
|
87
88
|
- lib/cucumber/lib/.DS_Store
|
@@ -91,6 +92,7 @@ files:
|
|
91
92
|
- lib/cucumber/lib/utils/ooor_utils.rb
|
92
93
|
- lib/cucumber/lib/utils/sequel_utils.rb
|
93
94
|
- lib/cucumber/openerp/dsl.rb
|
95
|
+
- lib/cucumber/openerp/dsl.rb.~1~
|
94
96
|
- lib/cucumber/openerp/world.rb
|
95
97
|
- lib/cucumber/openerp.rb
|
96
98
|
homepage:
|