efo_nelfo 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Guardfile +2 -1
- data/efo_nelfo.gemspec +1 -0
- data/lib/efo_nelfo/collection.rb +44 -0
- data/lib/efo_nelfo/errors.rb +4 -2
- data/lib/efo_nelfo/has_many.rb +70 -0
- data/lib/efo_nelfo/post_head_type.rb +30 -0
- data/lib/efo_nelfo/post_type.rb +26 -23
- data/lib/efo_nelfo/property.rb +18 -1
- data/lib/efo_nelfo/reader/csv.rb +1 -1
- data/lib/efo_nelfo/v40/{order/order.rb → bh.rb} +13 -45
- data/lib/efo_nelfo/v40/bl.rb +30 -0
- data/lib/efo_nelfo/v40/bt.rb +15 -0
- data/lib/efo_nelfo/v40/va.rb +11 -0
- data/lib/efo_nelfo/v40/vh.rb +24 -0
- data/lib/efo_nelfo/v40/vl.rb +34 -0
- data/lib/efo_nelfo/v40/vx.rb +9 -0
- data/lib/efo_nelfo/version.rb +1 -1
- data/lib/efo_nelfo.rb +10 -7
- data/spec/collection_spec.rb +68 -0
- data/spec/csv_writer_spec.rb +11 -11
- data/spec/efo_nelfo_spec.rb +76 -18
- data/spec/post_type_spec.rb +63 -0
- data/spec/property_spec.rb +14 -0
- data/spec/samples/rabatt.csv +1234 -0
- data/spec/samples/varefil_eksempel.csv +10 -0
- data/spec/samples/varer.csv +75429 -0
- data/spec/samples/varer_small.csv +10 -0
- data/spec/spec_helper.rb +7 -1
- metadata +39 -8
- data/lib/efo_nelfo/array.rb +0 -25
- data/lib/efo_nelfo/attribute_assignment.rb +0 -13
- data/lib/efo_nelfo/v40/order/line.rb +0 -50
- data/lib/efo_nelfo/v40/order/text.rb +0 -22
data/spec/csv_writer_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe EfoNelfo::V40::
|
5
|
-
let(:order) { EfoNelfo::V40::
|
4
|
+
describe EfoNelfo::V40::BH do
|
5
|
+
let(:order) { EfoNelfo::V40::BH.new buyer_id: '123', customer_id: '456' }
|
6
6
|
let(:csv) { order.to_csv }
|
7
7
|
|
8
8
|
describe "to_a" do
|
@@ -12,8 +12,8 @@ describe EfoNelfo::V40::Order do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "includes the lines" do
|
15
|
-
order.add EfoNelfo::V40::
|
16
|
-
order.add EfoNelfo::V40::
|
15
|
+
order.add EfoNelfo::V40::BL.new
|
16
|
+
order.add EfoNelfo::V40::BL.new
|
17
17
|
order.to_a.size.must_equal 3
|
18
18
|
end
|
19
19
|
|
@@ -21,8 +21,8 @@ describe EfoNelfo::V40::Order do
|
|
21
21
|
|
22
22
|
describe "to_csv" do
|
23
23
|
before do
|
24
|
-
order.add EfoNelfo::V40::
|
25
|
-
order.add EfoNelfo::V40::
|
24
|
+
order.add EfoNelfo::V40::BL.new order_number: 'foo', item_name: 'Ware', item_count: 6, splitable: true
|
25
|
+
order.add EfoNelfo::V40::BT.new text: 'haha'
|
26
26
|
end
|
27
27
|
|
28
28
|
it "includes standard fields" do
|
@@ -30,22 +30,22 @@ describe EfoNelfo::V40::Order do
|
|
30
30
|
csv.must_match /;4.0;/
|
31
31
|
csv.must_match /;123;/
|
32
32
|
csv.must_match /;600;/
|
33
|
-
csv.must_match /;J;/
|
33
|
+
csv.must_match /;J;/ # for fixing sublime syntax highlighting: /
|
34
34
|
end
|
35
35
|
|
36
36
|
it "can be parsed" do
|
37
37
|
o = EfoNelfo.parse(csv)
|
38
|
-
o.must_be_instance_of EfoNelfo::V40::
|
39
|
-
o.lines.first.text.must_be_instance_of EfoNelfo::V40::
|
38
|
+
o.must_be_instance_of EfoNelfo::V40::BH
|
39
|
+
o.lines.first.text.first.must_be_instance_of EfoNelfo::V40::BT
|
40
40
|
end
|
41
41
|
|
42
42
|
it "adds order lines" do
|
43
|
-
order.add EfoNelfo::V40::
|
43
|
+
order.add EfoNelfo::V40::BL.new(order_number: 'foo', item_name: 'Ware')
|
44
44
|
csv.must_match /Ware/
|
45
45
|
end
|
46
46
|
|
47
47
|
it "adds text to order line" do
|
48
|
-
csv.must_match /haha/
|
48
|
+
csv.must_match /BT;haha/
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
data/spec/efo_nelfo_spec.rb
CHANGED
@@ -10,19 +10,19 @@ describe EfoNelfo do
|
|
10
10
|
|
11
11
|
describe "properties" do
|
12
12
|
it "is accessible as alias" do
|
13
|
-
order = EfoNelfo::V40::
|
13
|
+
order = EfoNelfo::V40::BH.new
|
14
14
|
order.buyer_id = "123"
|
15
15
|
order.KjøpersId.must_equal "123"
|
16
16
|
end
|
17
17
|
|
18
18
|
it "can update the variable using the alias" do
|
19
|
-
order = EfoNelfo::V40::
|
19
|
+
order = EfoNelfo::V40::BH.new
|
20
20
|
order.KjøpersId = "foo"
|
21
21
|
order.buyer_id.must_equal "foo"
|
22
22
|
end
|
23
23
|
|
24
24
|
it "has custom setters" do
|
25
|
-
EfoNelfo::V40::
|
25
|
+
EfoNelfo::V40::BH.new(delivery_date: "20110402").delivery_date.must_be_kind_of Date
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
@@ -34,15 +34,17 @@ describe EfoNelfo do
|
|
34
34
|
seller_warehouse: "Somewhere",
|
35
35
|
label: "Some label",
|
36
36
|
lines: [
|
37
|
-
{ item_type: 1, order_number: "12345", item_name: "Foo", price_unit: "NOK" },
|
38
|
-
{ item_type: 1, order_number: "12345", item_name: "Bar", price_unit: "SEK", text:
|
37
|
+
{ post_type: 'BL', item_type: 1, order_number: "12345", item_name: "Foo", price_unit: "NOK" },
|
38
|
+
{ post_type: 'BL', item_type: 1, order_number: "12345", item_name: "Bar", price_unit: "SEK", text: [
|
39
|
+
{ post_type: 'BT', text: "some dummy lorem ipsum text" }
|
40
|
+
] }
|
39
41
|
]
|
40
42
|
}
|
41
43
|
}
|
42
|
-
let(:order) { EfoNelfo::V40::
|
44
|
+
let(:order) { EfoNelfo::V40::BH.new json }
|
43
45
|
|
44
46
|
it "creates an order" do
|
45
|
-
order.must_be_instance_of EfoNelfo::V40::
|
47
|
+
order.must_be_instance_of EfoNelfo::V40::BH
|
46
48
|
end
|
47
49
|
|
48
50
|
it "assigns attributes" do
|
@@ -52,15 +54,20 @@ describe EfoNelfo do
|
|
52
54
|
|
53
55
|
it "assigns order lines" do
|
54
56
|
order.lines.size.must_equal 2
|
57
|
+
order.lines.first.must_be_instance_of EfoNelfo::V40::BL
|
58
|
+
order.lines[0].item_name.must_equal "Foo"
|
59
|
+
order.lines[1].item_name.must_equal "Bar"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "adds index to the line items" do
|
55
63
|
order.lines[0].index.must_equal 1
|
56
64
|
order.lines[1].index.must_equal 2
|
57
|
-
order.lines[1].item_name.must_equal "Bar"
|
58
65
|
end
|
59
66
|
|
60
67
|
it "adds text to order lines" do
|
61
|
-
order.lines.first.text.
|
62
|
-
order.lines[1].text.must_be_instance_of EfoNelfo::V40::
|
63
|
-
order.lines[1].text.to_s.must_equal "
|
68
|
+
order.lines.first.text.must_be_empty
|
69
|
+
order.lines[1].text.first.must_be_instance_of EfoNelfo::V40::BT
|
70
|
+
order.lines[1].text.first.to_s.must_equal "some dummy lorem ipsum text"
|
64
71
|
end
|
65
72
|
|
66
73
|
end
|
@@ -84,6 +91,60 @@ describe EfoNelfo do
|
|
84
91
|
end
|
85
92
|
end
|
86
93
|
|
94
|
+
describe "passing a Product file" do
|
95
|
+
let(:nelfo) { EfoNelfo.load(csv('varefil_eksempel.csv')) }
|
96
|
+
|
97
|
+
it { nelfo.must_be_instance_of EfoNelfo::V40::VH }
|
98
|
+
|
99
|
+
it "loads the order" do
|
100
|
+
nelfo.format.must_equal "EFONELFO"
|
101
|
+
nelfo.version.must_equal "4.0"
|
102
|
+
nelfo.post_type.must_equal "VH"
|
103
|
+
nelfo.SelgersId.must_equal "NO1234567879MVA"
|
104
|
+
nelfo.KjøpersId.must_be_nil
|
105
|
+
nelfo.KundeNr.must_be_nil
|
106
|
+
nelfo.from_date.must_equal Date.new(2004, 1, 22)
|
107
|
+
nelfo.to_date.must_be_nil
|
108
|
+
nelfo.currency.must_equal "NOK"
|
109
|
+
nelfo.contract_id.must_be_nil
|
110
|
+
nelfo.seller_name.must_equal "ONNINEN A/S"
|
111
|
+
nelfo.seller_address1.must_equal "P.B. 70"
|
112
|
+
nelfo.seller_address2.must_be_nil
|
113
|
+
nelfo.seller_zip.must_equal "1483"
|
114
|
+
nelfo.seller_office.must_equal "SKYTTA"
|
115
|
+
nelfo.seller_country.must_equal "NO"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "adds product lines" do
|
119
|
+
nelfo.lines.count.must_equal 3
|
120
|
+
|
121
|
+
line = nelfo.lines.first
|
122
|
+
line.product_type.must_equal 1
|
123
|
+
line.product_number.must_equal "1006100"
|
124
|
+
line.name.must_equal "MATTE 3MM 100W/M2 100W"
|
125
|
+
line.description.must_equal "1,0 m2 0,5 x 2,0 m"
|
126
|
+
line.unit.must_equal 1
|
127
|
+
line.price_unit.must_equal "EA"
|
128
|
+
line.price_unit_desc.must_equal "STYKK"
|
129
|
+
line.price.must_equal 55300
|
130
|
+
line.amount.must_equal 10000
|
131
|
+
line.price_date.must_equal Date.new(2011,9,1)
|
132
|
+
line.status.must_equal 1
|
133
|
+
line.block_number.must_be_nil
|
134
|
+
line.discount_group.must_equal "1004"
|
135
|
+
line.fabrication.must_be_nil
|
136
|
+
line.type.must_be_nil
|
137
|
+
line.stocked.must_equal true
|
138
|
+
line.stocked?.must_equal true
|
139
|
+
line.sales_package.must_equal 10000
|
140
|
+
end
|
141
|
+
|
142
|
+
it "adds additional information to the product" do
|
143
|
+
line = nelfo.lines.first
|
144
|
+
line.info.first.value.must_equal "http://www.elektroskandia.no/image/products/1221102.gif"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
87
148
|
describe "passing a Order file" do
|
88
149
|
|
89
150
|
it "uses the correct version" do
|
@@ -91,13 +152,12 @@ describe EfoNelfo do
|
|
91
152
|
end
|
92
153
|
|
93
154
|
it "parses the file and returns an Order" do
|
94
|
-
EfoNelfo.load(csv('B650517.032.csv')).must_be_instance_of EfoNelfo::V40::
|
155
|
+
EfoNelfo.load(csv('B650517.032.csv')).must_be_instance_of EfoNelfo::V40::BH
|
95
156
|
end
|
96
157
|
|
97
158
|
it "the order contains order information" do
|
98
159
|
order = EfoNelfo.load(csv('B650517.032.csv'))
|
99
160
|
order.post_type.must_equal 'BH'
|
100
|
-
order.post_type_human.must_equal 'Bestilling Hodepost'
|
101
161
|
order.format.must_equal 'EFONELFO'
|
102
162
|
order.version.must_equal '4.0'
|
103
163
|
end
|
@@ -106,10 +166,9 @@ describe EfoNelfo do
|
|
106
166
|
order = EfoNelfo.load(csv('B650517.032.csv'))
|
107
167
|
|
108
168
|
line = order.lines.first
|
109
|
-
line.must_be_instance_of EfoNelfo::V40::
|
169
|
+
line.must_be_instance_of EfoNelfo::V40::BL
|
110
170
|
|
111
171
|
line.post_type.must_equal 'BL'
|
112
|
-
line.post_type_human.must_equal 'Bestilling vareLinjepost'
|
113
172
|
|
114
173
|
line.index.must_equal 1
|
115
174
|
line.order_number.must_equal '1465'
|
@@ -129,8 +188,7 @@ describe EfoNelfo do
|
|
129
188
|
|
130
189
|
it "adds text to orderline" do
|
131
190
|
order = EfoNelfo.load(csv('B650517.032.csv'))
|
132
|
-
|
133
|
-
line.text.to_s.must_equal "Her er litt fritekst"
|
191
|
+
order.lines.first.text.first.to_s.must_equal "Her er litt fritekst"
|
134
192
|
end
|
135
193
|
|
136
194
|
it "stores the contents file in the Order object" do
|
@@ -143,7 +201,7 @@ describe EfoNelfo do
|
|
143
201
|
# Loads all files in the samples directory
|
144
202
|
%w(B028579.594.csv B028579.596.csv B650517.031.csv B028579.595.csv B028579.597.csv B650517.030.csv B650517.032.csv).each do |file|
|
145
203
|
it "can load #{file}" do
|
146
|
-
EfoNelfo.load(csv(file)).must_be_instance_of EfoNelfo::V40::
|
204
|
+
EfoNelfo.load(csv(file)).must_be_instance_of EfoNelfo::V40::BH
|
147
205
|
end
|
148
206
|
end
|
149
207
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EfoNelfo::PostType do
|
4
|
+
|
5
|
+
module EfoNelfo
|
6
|
+
module V21
|
7
|
+
class Foo < EfoNelfo::PostType
|
8
|
+
property :post_type
|
9
|
+
property :version
|
10
|
+
property :seller_id
|
11
|
+
has_many :lines, :post_type => "Bar"
|
12
|
+
end
|
13
|
+
|
14
|
+
class Bar < EfoNelfo::PostType
|
15
|
+
property :post_type
|
16
|
+
property :order_number
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "versioning" do
|
22
|
+
|
23
|
+
it ".version_from_class returns the version" do
|
24
|
+
EfoNelfo::V21::Foo.version_from_class.must_equal "21"
|
25
|
+
end
|
26
|
+
|
27
|
+
it ".version returns the version as a number" do
|
28
|
+
EfoNelfo::V21::Foo.version.must_equal "2.1"
|
29
|
+
end
|
30
|
+
|
31
|
+
it ".version_to_namespace converts version to module name" do
|
32
|
+
EfoNelfo::V21::Foo.version_to_namespace("2.1").must_equal "21"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".from" do
|
38
|
+
let(:hash) {
|
39
|
+
{
|
40
|
+
post_type: "Foo",
|
41
|
+
version: "2.1",
|
42
|
+
seller_id: "123",
|
43
|
+
lines: [
|
44
|
+
{ post_type: "Bar", order_number: "666-2" }
|
45
|
+
]
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
let(:pt) { EfoNelfo::PostType.from hash }
|
50
|
+
|
51
|
+
it "converts the hash into a valid posttype" do
|
52
|
+
pt.must_be_instance_of EfoNelfo::V21::Foo
|
53
|
+
pt.seller_id.must_equal "123"
|
54
|
+
end
|
55
|
+
|
56
|
+
# it "adds lines" do
|
57
|
+
# pt.lines.size.must_equal 1
|
58
|
+
# pt.lines.first.order_number.must_equal "666-2"
|
59
|
+
# end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/spec/property_spec.rb
CHANGED
@@ -25,6 +25,15 @@ describe EfoNelfo::Property do
|
|
25
25
|
}.must_raise EfoNelfo::DuplicateProperty
|
26
26
|
end
|
27
27
|
|
28
|
+
it "raises an error if trying to assign an unsupported option" do
|
29
|
+
lambda {
|
30
|
+
class Bar
|
31
|
+
include EfoNelfo::Property
|
32
|
+
property :lame, funny: true
|
33
|
+
end
|
34
|
+
}.must_raise EfoNelfo::UnknownPropertyOption
|
35
|
+
end
|
36
|
+
|
28
37
|
it "adds a getter and setter for foo" do
|
29
38
|
obj.foo = 'Test'
|
30
39
|
obj.foo.must_equal 'Test'
|
@@ -118,6 +127,11 @@ describe EfoNelfo::Property do
|
|
118
127
|
end
|
119
128
|
end
|
120
129
|
|
130
|
+
it "#has_property? returns true when property exists" do
|
131
|
+
obj.has_property?(:foo).must_equal true
|
132
|
+
obj.has_property?(:bullshit).must_equal false
|
133
|
+
end
|
134
|
+
|
121
135
|
describe "#to_a" do
|
122
136
|
it "returns array of all attributes in correct order" do
|
123
137
|
obj.date = Date.new 2012, 5, 30
|