rs.ge 0.1.0.beta2 → 0.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'getting waybill units' do
5
+ before(:all) do
6
+ @units = RS.dict.units
7
+ end
8
+ subject { @units }
9
+ it { should_not be_nil }
10
+ it { should_not be_empty }
11
+ context 'kg' do
12
+ subject { @units[2] }
13
+ it { should == 'კგ' }
14
+ end
15
+ context 'others' do
16
+ subject { @units[RS::UNIT_OTHERS] }
17
+ it { should == 'სხვა' }
18
+ end
19
+ end
20
+
21
+ describe 'getting waybill types' do
22
+ before(:all) do
23
+ @types = RS.dict.waybill_types
24
+ end
25
+ subject { @types }
26
+ it { should_not be_nil }
27
+ it { should_not be_empty }
28
+ its(:size) { should == RS::WAYBILL_TYPES.size }
29
+ end
30
+
31
+ describe 'getting transport types' do
32
+ before(:all) do
33
+ @types = RS.dict.transport_types
34
+ end
35
+ subject { @types }
36
+ it { should_not be_nil }
37
+ it { should_not be_empty }
38
+ its(:size) { should == RS::TRANSPORT_TYPES.size }
39
+ end
40
+
41
+ describe 'getting payer name from tin' do
42
+ before(:all) do
43
+ @name = RS.dict.get_name_from_tin(tin: '02001000490')
44
+ end
45
+ subject { @name }
46
+ it { should == 'დიმიტრი ყურაშვილი' }
47
+ end
48
+
49
+ RSpec::Matchers.define :be_personal_tin do
50
+ match { |actual| RS.dict.personal_tin?(actual) }
51
+ end
52
+
53
+ RSpec::Matchers.define :be_corporate_tin do
54
+ match { |actual| RS.dict.corporate_tin?(actual) }
55
+ end
56
+
57
+ describe 'quick TIN validations' do
58
+ # personal
59
+ specify { '02001000490'.should be_personal_tin }
60
+ specify { '12345678901'.should be_personal_tin }
61
+ specify { '1234567890'.should_not be_personal_tin }
62
+ specify { '123456789012'.should_not be_personal_tin }
63
+ # corporate
64
+ specify { '422430239'.should be_corporate_tin }
65
+ specify { '123456789'.should be_corporate_tin }
66
+ specify { '1234567890'.should_not be_corporate_tin }
67
+ specify { '12345678'.should_not be_corporate_tin }
68
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'Save invoice' do
5
+ before(:all) do
6
+ @waybill = create_waybill(items: [create_item])
7
+ RS.wb.save_waybill(@waybill)
8
+ RS.wb.activate_waybill(id: @waybill.id)
9
+ RS.wb.close_waybill(id: @waybill.id)
10
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
11
+ @invoice_id = RS.wb.save_invoice(id: @waybill.id)
12
+ end
13
+ context 'Analyze' do
14
+ subject { @invoice_id }
15
+ it { should_not be_nil }
16
+ it { should > 0 }
17
+ end
18
+ context 'update waybill' do
19
+ before(:all) do
20
+ @waybill.items[0].price = 10
21
+ @waybill.items[0].quantity = 5
22
+ @resp = RS.wb.save_waybill(@waybill)
23
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
24
+ end
25
+ subject { @waybill }
26
+ its(:error_code) { should be_nil }
27
+ its(:total) { should == 50 }
28
+ end
29
+ context 'update invoice' do
30
+ before(:all) do
31
+ @new_invoice_id = RS.wb.save_invoice(id: @waybill.id, invoice_id: @invoice_id)
32
+ end
33
+ subject { @new_invoice_id }
34
+ it { should == @invoice_id }
35
+ end
36
+ end
@@ -0,0 +1,60 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'getting own IP address' do
5
+ before(:all) do
6
+ @ip = RS.sys.what_is_my_ip
7
+ end
8
+ subject { @ip }
9
+ it { should_not be_nil }
10
+ it { should_not be_empty }
11
+ it { should match /([0-9]{1,3}\.){3}[0-9]{1,3}/ }
12
+ end
13
+
14
+ describe 'working with service user' do
15
+ before(:all) do
16
+ @username = "user_#{Time.now.to_i}_#{rand(100)}"
17
+ @password = '123456'
18
+ @new_password = 'new_password_123456'
19
+ @ip = RS.sys.what_is_my_ip
20
+ @resp = RS.sys.create_user(USER01.merge(ip: @ip, name: 'test', su: @username, sp: @password))
21
+ end
22
+ subject { @resp }
23
+ it { should == true }
24
+ describe 'update service user' do
25
+ before(:all) do
26
+ @resp = RS.sys.update_user(USER01.merge(ip: @ip, name: 'test', su: @username, sp: @new_password))
27
+ end
28
+ subject { @resp }
29
+ it { should == true }
30
+ end
31
+ describe 'check service user: illegal user/password' do
32
+ before(:all) do
33
+ @resp = RS.sys.check_user(su: @username, sp: @password)
34
+ end
35
+ subject { @resp }
36
+ it { should be_nil }
37
+ end
38
+ describe 'check service user: legal user/password' do
39
+ before(:all) do
40
+ @resp = RS.sys.check_user(su: @username, sp: @new_password)
41
+ end
42
+ subject { @resp }
43
+ it { should_not be_nil }
44
+ specify { subject[:payer].should_not be_nil }
45
+ specify { subject[:user].should_not be_nil }
46
+ end
47
+ end
48
+
49
+ describe 'get error codes' do
50
+ before(:all) do
51
+ @errors = RS.sys.error_codes
52
+ end
53
+ subject { @errors }
54
+ it { should_not be_nil }
55
+ it { should_not be_empty }
56
+ context 'known error codes' do
57
+ subject { @errors[-2001] }
58
+ it { should == 'პროდუქტის დასახელება დიდია' }
59
+ end
60
+ end
@@ -0,0 +1,211 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'Save waybill' do
5
+ before(:all) do
6
+ items = [create_item(bar_code: '001', prod_name: 'პამიდორი', price: 2, quantity: 5), create_item(bar_code: '002', prod_name: 'კიტრი', price: 3, quantity: 10)]
7
+ @waybill = create_waybill(items: items)
8
+ RS.wb.save_waybill(@waybill)
9
+ end
10
+ context 'waybill' do
11
+ subject { @waybill }
12
+ its(:id) { should_not be_nil }
13
+ its(:id) { should > 0 }
14
+ its(:error_code) { should == 0 }
15
+ end
16
+ context 'items' do
17
+ subject { @waybill.items.first }
18
+ its(:id) { should_not be_nil }
19
+ its(:id) { should > 0 }
20
+ end
21
+ context 'get this waybill' do
22
+ before(:all) do
23
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
24
+ end
25
+ subject { @waybill }
26
+ it { should_not be_nil }
27
+ its(:id) { should > 0 }
28
+ its(:number) { should be_nil }
29
+ its(:status) { should == RS::Waybill::STATUS_SAVED }
30
+ its(:total) { should == 40 }
31
+ its(:create_date) { should_not be_nil }
32
+ its(:create_date) { should be_instance_of DateTime }
33
+ its(:activate_date) { should be_nil }
34
+ its(:close_date) { should be_nil }
35
+ its(:delivery_date) { should be_nil }
36
+ end
37
+ end
38
+
39
+ describe 'Resave waybill' do
40
+ before(:all) do
41
+ items = [create_item(bar_code: '100', prod_name: 'მობილური', price: 500, quantity: 1), create_item(bar_code: '101', prod_name: 'Kingston RAM/4GB/DDR3', price: 45, quantity: 2)]
42
+ @waybill = create_waybill(items: items)
43
+ RS.wb.save_waybill(@waybill)
44
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
45
+ @initial_id = @waybill.id
46
+ end
47
+ context 'After initial save' do
48
+ subject { @waybill }
49
+ its(:total) { should == 590 }
50
+ specify { subject.items.size.should == 2 }
51
+ end
52
+ context 'Delete first item and update second' do
53
+ before(:all) do
54
+ @waybill.items[0].delete = true
55
+ @waybill.items[1].quantity = 3
56
+ @waybill.items[1].price = 50
57
+ RS.wb.save_waybill(@waybill)
58
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
59
+ end
60
+ subject { @waybill }
61
+ its(:id) { should == @initial_id }
62
+ its(:total) { should == 150 }
63
+ specify { subject.items.size.should == 1 }
64
+ end
65
+ end
66
+
67
+ describe 'Activate waybill' do
68
+ context 'with begin_date' do
69
+ before(:all) do
70
+ items = [
71
+ create_item(bar_code: '001', prod_name: 'iPhone 4S 3G/32GB', price: 1800, quantity: 2),
72
+ create_item(bar_code: '002', prod_name: 'The New iPad 3G/16GB', price: 1200, quantity: 1)
73
+ ]
74
+ @waybill = create_waybill(items: items)
75
+ RS.wb.save_waybill(@waybill)
76
+ @resp = RS.wb.activate_waybill(id: @waybill.id, date: Time.now)
77
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
78
+ end
79
+ subject { @waybill }
80
+ its(:id) { should_not be_nil }
81
+ its(:total) { should == 4800 }
82
+ its(:number) { should_not be_nil }
83
+ its(:number) { should == @resp }
84
+ its(:status) { should == RS::Waybill::STATUS_ACTIVE }
85
+ its(:activate_date) { should_not be_nil }
86
+ its(:delivery_date) { should be_nil }
87
+ end
88
+ context 'without begin_date' do
89
+ before(:all) do
90
+ items = [
91
+ create_item(bar_code: '001', prod_name: 'iPhone 4S 3G/32GB', price: 1800, quantity: 2),
92
+ create_item(bar_code: '002', prod_name: 'The New iPad 3G/16GB', price: 1200, quantity: 1)
93
+ ]
94
+ @waybill = create_waybill(items: items)
95
+ RS.wb.save_waybill(@waybill)
96
+ @resp = RS.wb.activate_waybill(id: @waybill.id)
97
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
98
+ end
99
+ context 'analyze' do
100
+ subject { @waybill }
101
+ its(:id) { should_not be_nil }
102
+ specify { subject.items.size.should == 2 }
103
+ its(:total) { should == 4800 }
104
+ its(:number) { should_not be_nil }
105
+ its(:number) { should == @resp }
106
+ its(:status) { should == RS::Waybill::STATUS_ACTIVE }
107
+ its(:activate_date) { should_not be_nil }
108
+ its(:delivery_date) { should be_nil }
109
+ end
110
+ context 'edit active waybill' do
111
+ before(:all) do
112
+ @waybill.items[1].delete = true
113
+ @waybill.items[0].quantity = 1
114
+ @waybill.items[0].price = 1000
115
+ RS.wb.save_waybill(@waybill)
116
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
117
+ end
118
+ subject { @waybill }
119
+ specify { subject.items.size.should == 1 }
120
+ its(:total) { should == 1000 }
121
+ its(:status) { should == RS::Waybill::STATUS_ACTIVE }
122
+ its(:number) { should == @resp }
123
+ end
124
+ end
125
+ end
126
+
127
+ describe 'Close waybill' do
128
+ context 'with delivery_date' do
129
+ before(:all) do
130
+ items = [
131
+ create_item(bar_code: '001', prod_name: 'iPhone 4S 3G/32GB', price: 1800, quantity: 2),
132
+ create_item(bar_code: '002', prod_name: 'The New iPad 3G/16GB', price: 1200, quantity: 1)
133
+ ]
134
+ @waybill = create_waybill(items: items)
135
+ RS.wb.save_waybill(@waybill)
136
+ RS.wb.activate_waybill(id: @waybill.id, date: Time.now)
137
+ @resp = RS.wb.close_waybill(id: @waybill.id, date: Time.now)
138
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
139
+ end
140
+ subject { @waybill }
141
+ its(:id) { should_not be_nil }
142
+ its(:total) { should == 4800 }
143
+ its(:number) { should_not be_nil }
144
+ specify { @resp.should == true }
145
+ its(:status) { should == RS::Waybill::STATUS_CLOSED }
146
+ its(:activate_date) { should_not be_nil }
147
+ its(:delivery_date) { should_not be_nil }
148
+ end
149
+ context 'without delivery_date' do
150
+ before(:all) do
151
+ items = [
152
+ create_item(bar_code: '001', prod_name: 'iPhone 4S 3G/32GB', price: 1800, quantity: 2),
153
+ create_item(bar_code: '002', prod_name: 'The New iPad 3G/16GB', price: 1200, quantity: 1)
154
+ ]
155
+ @waybill = create_waybill(items: items)
156
+ RS.wb.save_waybill(@waybill)
157
+ RS.wb.activate_waybill(id: @waybill.id)
158
+ @resp = RS.wb.close_waybill(id: @waybill.id)
159
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
160
+ end
161
+ subject { @waybill }
162
+ its(:id) { should_not be_nil }
163
+ its(:total) { should == 4800 }
164
+ its(:number) { should_not be_nil }
165
+ specify { @resp.should == true }
166
+ its(:status) { should == RS::Waybill::STATUS_CLOSED }
167
+ its(:activate_date) { should_not be_nil }
168
+ its(:delivery_date) { should_not be_nil }
169
+ end
170
+ end
171
+
172
+ describe 'Delete waybill' do
173
+ context 'save and delete' do
174
+ before(:all) do
175
+ @waybill = create_waybill(items: [create_item])
176
+ RS.wb.save_waybill(@waybill)
177
+ @resp = RS.wb.delete_waybill(id: @waybill.id)
178
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
179
+ end
180
+ subject { @waybill }
181
+ specify { @resp.should == true }
182
+ its(:status) { should == RS::Waybill::STATUS_DELETED }
183
+ end
184
+ context 'save, activate and delete' do
185
+ before(:all) do
186
+ @waybill = create_waybill(items: [create_item])
187
+ RS.wb.save_waybill(@waybill)
188
+ RS.wb.activate_waybill(id: @waybill.id)
189
+ @resp = RS.wb.delete_waybill(id: @waybill.id)
190
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
191
+ end
192
+ subject { @waybill }
193
+ specify { @resp.should == false }
194
+ its(:status) { should == RS::Waybill::STATUS_ACTIVE }
195
+ end
196
+ end
197
+
198
+ describe 'Deactivate waybill' do
199
+ context 'save, activate and deactivate waybill' do
200
+ before(:all) do
201
+ @waybill = create_waybill(items: [create_item])
202
+ RS.wb.save_waybill(@waybill)
203
+ RS.wb.activate_waybill(id: @waybill.id)
204
+ @resp = RS.wb.deactivate_waybill(id: @waybill.id)
205
+ @waybill = RS.wb.get_waybill(id: @waybill.id)
206
+ end
207
+ subject { @waybill }
208
+ specify { @resp.should == true }
209
+ its(:status) { should == RS::Waybill::STATUS_DEACTIVATED }
210
+ end
211
+ end
data/spec/spec_helper.rb CHANGED
@@ -16,6 +16,9 @@ RSpec.configure do |config|
16
16
  config.include(RSpec::Matchers)
17
17
  end
18
18
 
19
- # Test user parameters.
19
+ # Test options.
20
20
 
21
- SU_PARAMS = {:su => 'dimitri1979', :sp => '123456'}
21
+ require 'helpers'
22
+
23
+ RS.config.su = 'dimtiri1979'
24
+ RS.config.sp = '123456'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rs.ge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta2
4
+ version: 0.1.0.rc1
5
5
  prerelease: 6
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: 2012-05-04 00:00:00.000000000 Z
12
+ date: 2012-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -32,17 +32,17 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - '='
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: 0.9.9
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: 0.9.9
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: httpi
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -105,12 +105,20 @@ files:
105
105
  - README.md
106
106
  - Rakefile
107
107
  - lib/rs.rb
108
- - lib/rs/models/waybill_unit.rb
109
- - lib/rs/requests/base_request.rb
110
- - lib/rs/requests/waybill_unit_request.rb
108
+ - lib/rs/models/waybill.rb
109
+ - lib/rs/requests/base.rb
110
+ - lib/rs/requests/config.rb
111
+ - lib/rs/requests/dict.rb
112
+ - lib/rs/requests/sys.rb
113
+ - lib/rs/requests/waybill.rb
111
114
  - lib/rs/version.rb
112
115
  - rs.gemspec
113
- - spec/requests/waybill_units_spec.rb
116
+ - spec/helpers.rb
117
+ - spec/models/waybill_spec.rb
118
+ - spec/requests/dict_spec.rb
119
+ - spec/requests/invoice_spec.rb
120
+ - spec/requests/sys_spec.rb
121
+ - spec/requests/waybill_spec.rb
114
122
  - spec/spec_helper.rb
115
123
  homepage: http://c12.ge
116
124
  licenses: []
@@ -132,8 +140,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
140
  version: 1.3.1
133
141
  requirements: []
134
142
  rubyforge_project: rs
135
- rubygems_version: 1.8.23
143
+ rubygems_version: 1.8.24
136
144
  signing_key:
137
145
  specification_version: 3
138
146
  summary: rs.ge web services
139
- test_files: []
147
+ test_files:
148
+ - spec/helpers.rb
149
+ - spec/models/waybill_spec.rb
150
+ - spec/requests/dict_spec.rb
151
+ - spec/requests/invoice_spec.rb
152
+ - spec/requests/sys_spec.rb
153
+ - spec/requests/waybill_spec.rb
154
+ - spec/spec_helper.rb