stockboy 0.5.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +5 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +12 -0
- data/Guardfile +10 -0
- data/LICENSE +21 -0
- data/README.md +293 -0
- data/Rakefile +30 -0
- data/lib/stockboy.rb +80 -0
- data/lib/stockboy/attribute.rb +11 -0
- data/lib/stockboy/attribute_map.rb +74 -0
- data/lib/stockboy/candidate_record.rb +130 -0
- data/lib/stockboy/configuration.rb +62 -0
- data/lib/stockboy/configurator.rb +176 -0
- data/lib/stockboy/dsl.rb +68 -0
- data/lib/stockboy/exceptions.rb +3 -0
- data/lib/stockboy/filter.rb +58 -0
- data/lib/stockboy/filter_chain.rb +41 -0
- data/lib/stockboy/filters.rb +11 -0
- data/lib/stockboy/filters/missing_email.rb +37 -0
- data/lib/stockboy/job.rb +241 -0
- data/lib/stockboy/mapped_record.rb +59 -0
- data/lib/stockboy/provider.rb +238 -0
- data/lib/stockboy/providers.rb +11 -0
- data/lib/stockboy/providers/file.rb +135 -0
- data/lib/stockboy/providers/ftp.rb +205 -0
- data/lib/stockboy/providers/http.rb +123 -0
- data/lib/stockboy/providers/imap.rb +290 -0
- data/lib/stockboy/providers/soap.rb +120 -0
- data/lib/stockboy/railtie.rb +28 -0
- data/lib/stockboy/reader.rb +59 -0
- data/lib/stockboy/readers.rb +11 -0
- data/lib/stockboy/readers/csv.rb +115 -0
- data/lib/stockboy/readers/fixed_width.rb +121 -0
- data/lib/stockboy/readers/spreadsheet.rb +144 -0
- data/lib/stockboy/readers/xml.rb +155 -0
- data/lib/stockboy/registry.rb +42 -0
- data/lib/stockboy/source_record.rb +43 -0
- data/lib/stockboy/string_pool.rb +35 -0
- data/lib/stockboy/template_file.rb +44 -0
- data/lib/stockboy/translations.rb +70 -0
- data/lib/stockboy/translations/boolean.rb +58 -0
- data/lib/stockboy/translations/date.rb +41 -0
- data/lib/stockboy/translations/decimal.rb +33 -0
- data/lib/stockboy/translations/default_empty_string.rb +38 -0
- data/lib/stockboy/translations/default_false.rb +41 -0
- data/lib/stockboy/translations/default_nil.rb +38 -0
- data/lib/stockboy/translations/default_true.rb +41 -0
- data/lib/stockboy/translations/default_zero.rb +41 -0
- data/lib/stockboy/translations/integer.rb +33 -0
- data/lib/stockboy/translations/string.rb +33 -0
- data/lib/stockboy/translations/time.rb +41 -0
- data/lib/stockboy/translations/uk_date.rb +51 -0
- data/lib/stockboy/translations/us_date.rb +51 -0
- data/lib/stockboy/translator.rb +66 -0
- data/lib/stockboy/version.rb +3 -0
- data/spec/fixtures/.gitkeep +0 -0
- data/spec/fixtures/files/a_garbage.csv +1 -0
- data/spec/fixtures/files/test_data-20120101.csv +1 -0
- data/spec/fixtures/files/test_data-20120202.csv +1 -0
- data/spec/fixtures/files/z_garbage.csv +1 -0
- data/spec/fixtures/jobs/test_job.rb +1 -0
- data/spec/fixtures/soap/get_list/fault.xml +8 -0
- data/spec/fixtures/soap/get_list/success.xml +18 -0
- data/spec/fixtures/spreadsheets/test_data.xls +0 -0
- data/spec/fixtures/spreadsheets/test_row_options.xls +0 -0
- data/spec/fixtures/xml/body.xml +14 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/stockboy/attribute_map_spec.rb +59 -0
- data/spec/stockboy/attribute_spec.rb +11 -0
- data/spec/stockboy/candidate_record_spec.rb +150 -0
- data/spec/stockboy/configuration_spec.rb +28 -0
- data/spec/stockboy/configurator_spec.rb +127 -0
- data/spec/stockboy/filter_chain_spec.rb +40 -0
- data/spec/stockboy/filter_spec.rb +41 -0
- data/spec/stockboy/filters/missing_email_spec.rb +26 -0
- data/spec/stockboy/filters_spec.rb +38 -0
- data/spec/stockboy/job_spec.rb +238 -0
- data/spec/stockboy/mapped_record_spec.rb +30 -0
- data/spec/stockboy/provider_spec.rb +34 -0
- data/spec/stockboy/providers/file_spec.rb +116 -0
- data/spec/stockboy/providers/ftp_spec.rb +143 -0
- data/spec/stockboy/providers/http_spec.rb +94 -0
- data/spec/stockboy/providers/imap_spec.rb +76 -0
- data/spec/stockboy/providers/soap_spec.rb +107 -0
- data/spec/stockboy/providers_spec.rb +38 -0
- data/spec/stockboy/readers/csv_spec.rb +68 -0
- data/spec/stockboy/readers/fixed_width_spec.rb +52 -0
- data/spec/stockboy/readers/spreadsheet_spec.rb +121 -0
- data/spec/stockboy/readers/xml_spec.rb +94 -0
- data/spec/stockboy/readers_spec.rb +30 -0
- data/spec/stockboy/source_record_spec.rb +19 -0
- data/spec/stockboy/template_file_spec.rb +30 -0
- data/spec/stockboy/translations/boolean_spec.rb +48 -0
- data/spec/stockboy/translations/date_spec.rb +38 -0
- data/spec/stockboy/translations/decimal_spec.rb +23 -0
- data/spec/stockboy/translations/default_empty_string_spec.rb +32 -0
- data/spec/stockboy/translations/default_false_spec.rb +25 -0
- data/spec/stockboy/translations/default_nil_spec.rb +32 -0
- data/spec/stockboy/translations/default_true_spec.rb +25 -0
- data/spec/stockboy/translations/default_zero_spec.rb +32 -0
- data/spec/stockboy/translations/integer_spec.rb +22 -0
- data/spec/stockboy/translations/string_spec.rb +22 -0
- data/spec/stockboy/translations/time_spec.rb +27 -0
- data/spec/stockboy/translations/uk_date_spec.rb +37 -0
- data/spec/stockboy/translations/us_date_spec.rb +37 -0
- data/spec/stockboy/translations_spec.rb +55 -0
- data/spec/stockboy/translator_spec.rb +27 -0
- data/stockboy.gemspec +32 -0
- metadata +305 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/boolean'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::Boolean do
|
|
6
|
+
|
|
7
|
+
describe "#call" do
|
|
8
|
+
def self.it_should_be(actual, arg)
|
|
9
|
+
it "returns #{actual.inspect} for #{arg[:for].inspect}" do
|
|
10
|
+
result = subject.call arg[:for]
|
|
11
|
+
result.should eq actual
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
subject { described_class.new(:bool) }
|
|
16
|
+
|
|
17
|
+
it_should_be false, for: {bool: false}
|
|
18
|
+
it_should_be true, for: {bool: true}
|
|
19
|
+
|
|
20
|
+
it_should_be false, for: {bool: 0 }
|
|
21
|
+
it_should_be false, for: {bool: '0'}
|
|
22
|
+
it_should_be false, for: {bool: 'f'}
|
|
23
|
+
it_should_be false, for: {bool: 'F'}
|
|
24
|
+
it_should_be false, for: {bool: 'false'}
|
|
25
|
+
it_should_be false, for: {bool: 'FALSE'}
|
|
26
|
+
it_should_be false, for: {bool: 'n'}
|
|
27
|
+
it_should_be false, for: {bool: 'N'}
|
|
28
|
+
it_should_be false, for: {bool: 'no'}
|
|
29
|
+
it_should_be false, for: {bool: 'NO'}
|
|
30
|
+
|
|
31
|
+
it_should_be true, for: {bool: 1 }
|
|
32
|
+
it_should_be true, for: {bool: '1'}
|
|
33
|
+
it_should_be true, for: {bool: 't'}
|
|
34
|
+
it_should_be true, for: {bool: 'T'}
|
|
35
|
+
it_should_be true, for: {bool: 'y'}
|
|
36
|
+
it_should_be true, for: {bool: 'Y'}
|
|
37
|
+
it_should_be true, for: {bool: 'yes'}
|
|
38
|
+
it_should_be true, for: {bool: 'YES'}
|
|
39
|
+
it_should_be true, for: {bool: 'true'}
|
|
40
|
+
it_should_be true, for: {bool: 'TRUE'}
|
|
41
|
+
|
|
42
|
+
it_should_be nil, for: {bool: nil}
|
|
43
|
+
it_should_be nil, for: {bool: '' }
|
|
44
|
+
it_should_be nil, for: {bool: 'anything else'}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/date'
|
|
3
|
+
require 'active_support/time'
|
|
4
|
+
|
|
5
|
+
module Stockboy
|
|
6
|
+
describe Translations::Date do
|
|
7
|
+
|
|
8
|
+
subject { described_class.new(:start) }
|
|
9
|
+
|
|
10
|
+
describe "#call" do
|
|
11
|
+
it "returns nil for an empty string" do
|
|
12
|
+
result = subject.call start: ""
|
|
13
|
+
result.should be_nil
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "returns a date unmodified" do
|
|
17
|
+
result = subject.call start: ::Date.new(2012,12,21)
|
|
18
|
+
result.should == ::Date.new(2012,12,21)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "returns a date from a string" do
|
|
22
|
+
result = subject.call start: '2013-12-11'
|
|
23
|
+
result.should == ::Date.new(2013,12,11)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "returns a date from a time" do
|
|
27
|
+
result = subject.call start: ::Time.new(2012,12,21,12,21,12)
|
|
28
|
+
result.should == ::Date.new(2012,12,21)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "returns a date from a DateTime" do
|
|
32
|
+
result = subject.call start: ::DateTime.new(2012,12,21,12,21,12)
|
|
33
|
+
result.should == ::Date.new(2012,12,21)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/decimal'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::Decimal do
|
|
6
|
+
|
|
7
|
+
subject { described_class.new(:total) }
|
|
8
|
+
|
|
9
|
+
describe "#call" do
|
|
10
|
+
it "returns nil for an empty string" do
|
|
11
|
+
result = subject.call total: ""
|
|
12
|
+
result.should be_nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns a decimal" do
|
|
16
|
+
result = subject.call total: "42.42"
|
|
17
|
+
result.should == 42.42
|
|
18
|
+
result.should be_a BigDecimal
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/default_empty_string'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::DefaultEmptyString do
|
|
6
|
+
|
|
7
|
+
subject { described_class.new(:comment) }
|
|
8
|
+
|
|
9
|
+
describe "#call" do
|
|
10
|
+
it "returns empty string for nil" do
|
|
11
|
+
result = subject.call comment: nil
|
|
12
|
+
result.should == ""
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns empty string for an empty string" do
|
|
16
|
+
result = subject.call comment: ""
|
|
17
|
+
result.should == ""
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "returns original value if present" do
|
|
21
|
+
result = subject.call comment: "asdf"
|
|
22
|
+
result.should == "asdf"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "returns original value when zero" do
|
|
26
|
+
result = subject.call comment: 0
|
|
27
|
+
result.should == 0
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/default_false'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::DefaultFalse do
|
|
6
|
+
|
|
7
|
+
describe "#call" do
|
|
8
|
+
def self.it_should_be(actual, arg)
|
|
9
|
+
it "returns #{actual.inspect} for #{arg[:for].inspect}" do
|
|
10
|
+
result = subject.call arg[:for]
|
|
11
|
+
result.should eq actual
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
subject { described_class.new(:bool) }
|
|
16
|
+
|
|
17
|
+
it_should_be false, for: {bool: false}
|
|
18
|
+
it_should_be true, for: {bool: true}
|
|
19
|
+
|
|
20
|
+
it_should_be false, for: {bool: nil}
|
|
21
|
+
it_should_be '', for: {bool: '' }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/default_nil'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::DefaultNil do
|
|
6
|
+
|
|
7
|
+
subject { described_class.new(:email) }
|
|
8
|
+
|
|
9
|
+
describe "#call" do
|
|
10
|
+
it "returns nil for empty string" do
|
|
11
|
+
result = subject.call email: ""
|
|
12
|
+
result.should == nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns nil for nil" do
|
|
16
|
+
result = subject.call email: nil
|
|
17
|
+
result.should == nil
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "returns original value if present" do
|
|
21
|
+
result = subject.call email: "a@example.com"
|
|
22
|
+
result.should == "a@example.com"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "returns original value when zero" do
|
|
26
|
+
result = subject.call email: 0
|
|
27
|
+
result.should == 0
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/default_true'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::DefaultTrue do
|
|
6
|
+
|
|
7
|
+
describe "#call" do
|
|
8
|
+
def self.it_should_be(actual, arg)
|
|
9
|
+
it "returns #{actual.inspect} for #{arg[:for].inspect}" do
|
|
10
|
+
result = subject.call arg[:for]
|
|
11
|
+
result.should eq actual
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
subject { described_class.new(:bool) }
|
|
16
|
+
|
|
17
|
+
it_should_be false, for: {bool: false}
|
|
18
|
+
it_should_be true, for: {bool: true}
|
|
19
|
+
|
|
20
|
+
it_should_be true, for: {bool: nil}
|
|
21
|
+
it_should_be '', for: {bool: '' }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/default_zero'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::DefaultZero do
|
|
6
|
+
|
|
7
|
+
subject { described_class.new(:count) }
|
|
8
|
+
|
|
9
|
+
describe "#call" do
|
|
10
|
+
it "returns zero for nil" do
|
|
11
|
+
result = subject.call count: nil
|
|
12
|
+
result.should == 0
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns zero for empty string" do
|
|
16
|
+
result = subject.call count: ""
|
|
17
|
+
result.should == 0
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "returns original value if present" do
|
|
21
|
+
result = subject.call count: 42
|
|
22
|
+
result.should == 42
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "returns original value when zero" do
|
|
26
|
+
result = subject.call count: 0
|
|
27
|
+
result.should == 0
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/integer'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::Integer do
|
|
6
|
+
|
|
7
|
+
subject { described_class.new(:id) }
|
|
8
|
+
|
|
9
|
+
describe "#call" do
|
|
10
|
+
it "returns nil for an empty string" do
|
|
11
|
+
result = subject.call id: ""
|
|
12
|
+
result.should be_nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns an integer" do
|
|
16
|
+
result = subject.call id: "42"
|
|
17
|
+
result.should == 42
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/string'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::String do
|
|
6
|
+
|
|
7
|
+
subject { described_class.new(:name) }
|
|
8
|
+
|
|
9
|
+
describe "#call" do
|
|
10
|
+
it "returns '' for nil" do
|
|
11
|
+
result = subject.call name: nil
|
|
12
|
+
result.should == ""
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "strips trailing & leading whitespace" do
|
|
16
|
+
result = subject.call name: " Arthur \n"
|
|
17
|
+
result.should == "Arthur"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/time'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::Time do
|
|
6
|
+
|
|
7
|
+
subject { described_class.new(:start) }
|
|
8
|
+
|
|
9
|
+
describe "#call" do
|
|
10
|
+
it "returns nil for an empty string" do
|
|
11
|
+
result = subject.call start: ""
|
|
12
|
+
result.should be_nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns a time" do
|
|
16
|
+
result = subject.call start: "2013-12-11 10:09:08"
|
|
17
|
+
result.should == Time.utc(2013,12,11,10,9,8)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "respects timezone" do
|
|
21
|
+
result = subject.call start: "2013-12-11 10:09:08 -0800"
|
|
22
|
+
result.should == Time.utc(2013,12,11,18,9,8)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/uk_date.rb'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::UKDate do
|
|
6
|
+
|
|
7
|
+
subject { described_class.new(:start) }
|
|
8
|
+
|
|
9
|
+
describe "#call" do
|
|
10
|
+
it "returns nil for an empty string" do
|
|
11
|
+
result = subject.call start: ""
|
|
12
|
+
result.should be_nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "translates DD/MM/YYYY" do
|
|
16
|
+
result = subject.call start: "15/4/2013"
|
|
17
|
+
result.should == Date.new(2013,4,15)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "translates DD/MM/YY" do
|
|
21
|
+
result = subject.call start: "15/4/13"
|
|
22
|
+
result.should == Date.new(2013,4,15)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "translates DD-MM-YYYY" do
|
|
26
|
+
result = subject.call start: "15-4-2013"
|
|
27
|
+
result.should == Date.new(2013,4,15)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "translates DD-MM-YY" do
|
|
31
|
+
result = subject.call start: "15-4-13"
|
|
32
|
+
result.should == Date.new(2013,4,15)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations/us_date.rb'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations::USDate do
|
|
6
|
+
|
|
7
|
+
subject { described_class.new(:start) }
|
|
8
|
+
|
|
9
|
+
describe "#call" do
|
|
10
|
+
it "returns nil for an empty string" do
|
|
11
|
+
result = subject.call start: ""
|
|
12
|
+
result.should be_nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "translates MM/DD/YYYY" do
|
|
16
|
+
result = subject.call start: "4/6/2013"
|
|
17
|
+
result.should == Date.new(2013,4,6)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "translates MM/DD/YY" do
|
|
21
|
+
result = subject.call start: "4/6/13"
|
|
22
|
+
result.should == Date.new(2013,4,6)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "translates MM-DD-YYYY" do
|
|
26
|
+
result = subject.call start: "4-6-2013"
|
|
27
|
+
result.should == Date.new(2013,4,6)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "translates MM-DD-YY" do
|
|
31
|
+
result = subject.call start: "4-6-13"
|
|
32
|
+
result.should == Date.new(2013,4,6)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'stockboy/translations'
|
|
3
|
+
|
|
4
|
+
module Stockboy
|
|
5
|
+
describe Translations do
|
|
6
|
+
|
|
7
|
+
subject { Translations }
|
|
8
|
+
|
|
9
|
+
describe ".register" do
|
|
10
|
+
it "accepts a class with method #call" do
|
|
11
|
+
translation_class = Class
|
|
12
|
+
allow(translation_class).to receive(:call)
|
|
13
|
+
Translations.register(:from_class, translation_class)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "accepts a callable method" do
|
|
17
|
+
translation_method = "Mr. ".public_method(:<<)
|
|
18
|
+
Translations.register :from_method, translation_method
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "accepts a lambda" do
|
|
22
|
+
translation_lambda = ->(i){ i.some_method }
|
|
23
|
+
Translations.register :from_lambda, translation_lambda
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "rejects non-callable objects" do
|
|
27
|
+
expect { Translations.register(:wrong, Object) }.to raise_error
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe ".translate" do
|
|
32
|
+
it "translates a string" do
|
|
33
|
+
Translations.register :personalize, "Dear Mr. ".public_method(:<<)
|
|
34
|
+
|
|
35
|
+
Translations.translate(:personalize, "Fun").should == "Dear Mr. Fun"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "translates from a proc" do
|
|
39
|
+
myproc = proc { |context| "Dear Mr. #{context[:first_name]}" }
|
|
40
|
+
Translations.translate(myproc, {first_name: "Fun"}).should == "Dear Mr. Fun"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe ".find" do
|
|
45
|
+
it "returns a callable translator" do
|
|
46
|
+
callable = ->(i){ i.upcase }
|
|
47
|
+
Translations.register :shout, callable
|
|
48
|
+
|
|
49
|
+
Translations.find(:shout).should == callable
|
|
50
|
+
Translations[:shout].should == callable
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|