~c2c-oerpscenario/oerpscenario/stable-6.0

« back to all changes in this revision

Viewing changes to features/samples/step_definitions/samples_steps.rb

  • Committer: Joël Grand-Guillaume
  • Date: 2010-03-26 11:30:57 UTC
  • mfrom: (30.1.75 OERPScenario)
  • Revision ID: joel.grandguillaume@camptocamp.com-20100326113057-w6jb16avnxkf2ize
[MRG] From trunk branch. This is about releasing the 0.5 version of OERPScenario.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
#
20
20
##############################################################################
21
 
Before do
22
 
    @res = false
23
 
    @part = false
24
 
    @account_id = false
25
 
    @prod = false
26
 
end
27
 
 
28
 
##############################################################################
29
 
Then /^I should get account_payable and pricelist proprety$/ do
30
 
 part = ResPartner.find(@part.id, :fields => ["property_account_payable","property_account_receivable"])
31
 
 part.property_account_payable.should be_true
32
 
 part.property_account_receivable.should be_true
33
 
 
34
 
end
35
 
 
36
 
##############################################################################
37
 
Given /^I want to create a partner named (\w+)$/ do |name|
38
 
     @part = ResPartner.new(:name => "#{name}, #{rand.to_s[0..10]}")
39
 
     @part.create.should be_true
40
 
end
41
 
 
42
 
##############################################################################
43
 
Then /^I copy the partner$/ do
44
 
end
45
 
 
46
 
##############################################################################
47
 
Then /^I should get a copied partner id$/ do
48
 
  pending
49
 
  res = @part.copy() #copy function ot found
50
 
   res.should be_true
51
 
end
52
 
 
53
 
##############################################################################
54
 
Given /^I want to create a prodcut named (.*)$/ do |name|
55
 
  @prod = ProductProduct.new(:name => "#{name}, #{rand.to_s[0..10]}")
56
 
  @prod.should be_true
57
 
end
58
 
 
59
 
##############################################################################
60
 
Then /^I get a product category$/ do
61
 
  res  = ProductCategory.find(:first)
62
 
  res.should be_true
63
 
  @prod.categ_id = res.id
64
 
end
65
 
 
66
 
##############################################################################
67
 
Then /^I should get a product id$/ do
68
 
  @prod.create.should be_true
69
 
end
70
 
 
71
 
##############################################################################
72
 
Then /^I should get property_expense_account and property_income_account proprety$/ do
73
 
    prod = ProductProduct.find(@prod.id, :fields => ["property_account_income","property_account_expense"])
74
 
    prod.property_account_income.should be_true
75
 
    prod.property_account_expense.should be_true
76
 
end
77
 
 
78
 
##############################################################################
79
 
Given /^I want to create a prodcut to copy named automatedtestprodcutcopy$/ do
80
 
  pending
81
 
end
82
 
 
83
 
##############################################################################
84
 
Then /^I copy the product$/ do
85
 
  pending
86
 
end
87
 
 
 
21
 
 
22
# ##############################################################################
 
23
# Scenario: Sample Create a partner and test some basic stuffs
 
24
# ##############################################################################
 
25
Given /^I want to show you how to use OERPScenario$/ do
 
26
  # Empty to pass (no need for an action)
 
27
end
 
28
 
 
29
# ##############################################################################
 
30
When /^I create a partner named (\w+)$/ do |name|
 
31
  # Create a new partner using Ooor, and store it in a
 
32
  # global var for the current feature
 
33
  @partner = ResPartner.new(:name => name)
 
34
  @partner.create
 
35
  # Controle it has been a success
 
36
  @partner.should be_true
 
37
end
 
38
 
 
39
# ##############################################################################
 
40
Then /^I should be able to find it by his id$/ do
 
41
  # Find the partner by id
 
42
  result=ResPartner.find(@partner.id)
 
43
  # Test we get something
 
44
  result.should be_true
 
45
  # Store it into @partner to have it for the next step
 
46
  @partner=result
 
47
end
 
48
 
 
49
# ##############################################################################
 
50
Then /^the name should be (\w+)$/ do |name|
 
51
  # Test the name is correct
 
52
  @partner.name.should == name
 
53
end
 
54
 
 
55
 
 
56
# ##############################################################################
 
57
# Scenario: Sample using the memorizer
 
58
# ##############################################################################
 
59
Given /^I am still in the same features and not the same scenario$/ do
 
60
  # Empty to pass (no need for an action)
 
61
end
 
62
 
 
63
# ##############################################################################
 
64
When /^I call the @partner variable I should not retrieve the partner$/ do
 
65
  # Check it contain nothing
 
66
  @partner.should be_false
 
67
end
 
68
 
 
69
# ##############################################################################
 
70
Given /^I take the first found partner to set @partner variable$/ do
 
71
  @partner=ResPartner.find(:first)
 
72
  @partner.should be_true
 
73
end
 
74
 
 
75
# ##############################################################################
 
76
Given /^I store it into the memorizer as (\w+) in order to retrieve it in another scenario$/ do |var_name|
 
77
  # Memorize the partner in order
 
78
  # to retrieve it again when needed in another
 
79
  # scenario or feature
 
80
  $utils.set_var(var_name,@partner)
 
81
end
 
82
 
 
83
# ##############################################################################
 
84
Given /^I call back the memorizer to retieve the (\w+) variable$/ do |var_name|
 
85
  @Memorized_partner=$utils.get_var(var_name.strip).should be_true
 
86
end
 
87
 
 
88
# ##############################################################################
 
89
Then /^I should have the same partner as contained into @partner variable$/ do
 
90
  @Memorized_partner.id.should == @partner.id
 
91
end
 
92
 
 
93
# ##############################################################################
 
94
# Scenario: Sample using ResPartner Helper
 
95
# ##############################################################################
 
96
Given /^I want to show you how to use the Helpers$/ do
 
97
 
 
98
end
 
99
 
 
100
# ##############################################################################
 
101
When /^you need to look for a supplier partner with at least one contact$/ do
 
102
 
 
103
end
 
104
 
 
105
# ##############################################################################
 
106
Then /^you can use one of the ResPartner helper called get_valid_partner$/ do
 
107
  # Use the ResPartner Helper to get a partner of a certain type
 
108
  # and with at least one address
 
109
  @partner=ResPartner.get_valid_partner({:type=>'supplier'})
 
110
  @partner.should be_true
 
111
end
 
112
 
 
113
# ##############################################################################
 
114
Then /^get the corresponding partner very easily$/ do
 
115
  # Check it's a supplier
 
116
  @partner.supplier.should be_true
 
117
  # Check it has a contact
 
118
  @partner.address.count.should > 0
 
119
end
 
120
 
 
121
 
 
122
 
 
123
 
 
124
# ##############################################################################
 
125
# Scenario: Sample using object method like validate an invoice
 
126
# ##############################################################################
 
127
Given /^I have recorded a supplier invoice of (.*) (\w+) called (\w+) using Helpers$/ do |amount, currency, name|
 
128
  # Take first supplier partner with at least one address
 
129
  @partner=ResPartner.get_valid_partner({:type=>'supplier'})
 
130
  @partner.should be_true
 
131
  # Create an invoice with a line = amount
 
132
  @invoice=AccountInvoice.create_invoice_with_currency(name, @partner, 
 
133
    {:currency_code=>currency, :amount=>amount.to_f, :type=>'in_invoice'})
 
134
  @invoice.should be_true
 
135
end
 
136
 
 
137
# ##############################################################################
 
138
When /^I validate the invoice using the validate button$/ do
 
139
  # Call the 'invoice_open' method from account.invoice openobject
 
140
  @invoice.wkf_action('invoice_open')
 
141
end
 
142
 
 
143
# ##############################################################################
 
144
Then /^I should get the invoice (\w+)$/ do |state|
 
145
  # Take the invoice and check the state
 
146
  @invoice.should be_true
 
147
  @invoice.state.should == state
 
148
end
 
149
 
 
150
 
 
151
# ##############################################################################
 
152
# Scenario: Sample to create and rename a partner
 
153
# ##############################################################################
 
154
Given /^I have created a partner named "([^\"]*)" with the following addresses:$/ do |name, table|
 
155
  # table is a Cucumber::Ast::Table
 
156
  @partner = ResPartner.new(:name => name)
 
157
  @partner.create
 
158
  @partner.should be_true
 
159
  table.hashes.each do |adress|
 
160
    add = ResPartnerAddress.new(:name => adress[:name],:partner_id => @partner.id)
 
161
    add.create
 
162
  end
 
163
  @partner = ResPartner.find(@partner.id)
 
164
  @partner.address.count.should == table.hashes.count
 
165
end
 
166
 
 
167
# ##############################################################################
 
168
Then /^.*expect.* partner (\w+) to be "?([^"]+)"?$/ do |field,value|
 
169
    @partner.send(field).to_s.should == value
 
170
end
 
171
 
 
172
# ##############################################################################
 
173
When /^I change the partner name to "([^\"]*)"$/ do |name|
 
174
  @partner.name = name
 
175
  @partner.save
 
176
end
 
177
 
 
178
# ##############################################################################
 
179
Then /^the partner name to be "([^\"]*)"$/ do |name|
 
180
  @partner.reload
 
181
  @partner.name.should == name
 
182
end