Skip to content

Commit 42416ff

Browse files
authored
Merge pull request Empact#56 from romuloceccon/support-ruby-2.4
Support Ruby 2.4
2 parents 076f78c + be3f32c commit 42416ff

9 files changed

Lines changed: 96 additions & 97 deletions

File tree

‎Gemfile‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
source "http://rubygems.org"
22

3-
gem 'activesupport', '>= 2.3.0'
3+
gem 'activesupport', '~> 3.1'
44
gem 'nokogiri', '>= 1.3.3'
55

66
group :development, :test do
7-
gem 'rake'
7+
gem 'rake', '~> 0.9'
88
gem 'jeweler'
9-
gem "rspec", '>= 2.0.0'
10-
gem "sqlite3-ruby", '>= 1.2.4'
11-
gem "activerecord", '>= 2.2.2'
9+
gem 'test-unit'
10+
gem 'rspec', '~> 2.8.0'
11+
gem 'sqlite3', '>= 1.2.4'
12+
gem 'activerecord', '~> 3.1'
1213
end

‎Gemfile.lock‎

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,66 @@
11
GEM
22
remote: http://rubygems.org/
33
specs:
4-
activemodel (3.1.3)
5-
activesupport (= 3.1.3)
4+
activemodel (3.2.22.5)
5+
activesupport (= 3.2.22.5)
66
builder (~> 3.0.0)
7-
i18n (~> 0.6)
8-
activerecord (3.1.3)
9-
activemodel (= 3.1.3)
10-
activesupport (= 3.1.3)
11-
arel (~> 2.2.1)
7+
activerecord (3.2.22.5)
8+
activemodel (= 3.2.22.5)
9+
activesupport (= 3.2.22.5)
10+
arel (~> 3.0.2)
1211
tzinfo (~> 0.3.29)
13-
activesupport (3.1.3)
12+
activesupport (3.2.22.5)
13+
i18n (~> 0.6, >= 0.6.4)
1414
multi_json (~> 1.0)
15-
arel (2.2.1)
16-
builder (3.0.0)
15+
addressable (2.4.0)
16+
arel (3.0.3)
17+
builder (3.0.4)
18+
descendants_tracker (0.0.4)
19+
thread_safe (~> 0.3, >= 0.3.1)
1720
diff-lcs (1.1.3)
18-
git (1.2.5)
19-
i18n (0.6.0)
20-
jeweler (1.6.4)
21-
bundler (~> 1.0)
21+
faraday (0.9.2)
22+
multipart-post (>= 1.2, < 3)
23+
git (1.3.0)
24+
github_api (0.16.0)
25+
addressable (~> 2.4.0)
26+
descendants_tracker (~> 0.0.4)
27+
faraday (~> 0.8, < 0.10)
28+
hashie (>= 3.4)
29+
mime-types (>= 1.16, < 3.0)
30+
oauth2 (~> 1.0)
31+
hashie (3.5.6)
32+
highline (1.7.8)
33+
i18n (0.8.6)
34+
jeweler (2.3.7)
35+
builder
36+
bundler (>= 1)
2237
git (>= 1.2.5)
38+
github_api (~> 0.16.0)
39+
highline (>= 1.6.15)
40+
nokogiri (>= 1.5.10)
41+
psych (~> 2.2)
2342
rake
24-
multi_json (1.0.4)
25-
nokogiri (1.5.0)
26-
rake (0.9.2.2)
43+
rdoc
44+
semver2
45+
jwt (1.5.6)
46+
mime-types (2.99.3)
47+
mini_portile2 (2.2.0)
48+
multi_json (1.12.1)
49+
multi_xml (0.6.0)
50+
multipart-post (2.0.0)
51+
nokogiri (1.8.0)
52+
mini_portile2 (~> 2.2.0)
53+
oauth2 (1.4.0)
54+
faraday (>= 0.8, < 0.13)
55+
jwt (~> 1.0)
56+
multi_json (~> 1.3)
57+
multi_xml (~> 0.5)
58+
rack (>= 1.2, < 3)
59+
power_assert (1.0.2)
60+
psych (2.2.4)
61+
rack (2.0.3)
62+
rake (0.9.6)
63+
rdoc (5.1.0)
2764
rspec (2.8.0)
2865
rspec-core (~> 2.8.0)
2966
rspec-expectations (~> 2.8.0)
@@ -32,19 +69,25 @@ GEM
3269
rspec-expectations (2.8.0)
3370
diff-lcs (~> 1.1.2)
3471
rspec-mocks (2.8.0)
35-
sqlite3 (1.3.5)
36-
sqlite3-ruby (1.3.3)
37-
sqlite3 (>= 1.3.3)
38-
tzinfo (0.3.31)
72+
semver2 (3.4.2)
73+
sqlite3 (1.3.13)
74+
test-unit (3.2.5)
75+
power_assert
76+
thread_safe (0.3.6)
77+
tzinfo (0.3.53)
3978

4079
PLATFORMS
4180
ruby
4281

4382
DEPENDENCIES
44-
activerecord (>= 2.2.2)
45-
activesupport (>= 2.3.0)
83+
activerecord (~> 3.1)
84+
activesupport (~> 3.1)
4685
jeweler
4786
nokogiri (>= 1.3.3)
48-
rake
49-
rspec (>= 2.0.0)
50-
sqlite3-ruby (>= 1.2.4)
87+
rake (~> 0.9)
88+
rspec (~> 2.8.0)
89+
sqlite3 (>= 1.2.4)
90+
test-unit
91+
92+
BUNDLED WITH
93+
1.15.2

‎lib/roxml.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def roxml_naming_convention # :nodoc:
260260
#
261261
# xml_reader(:count) {|val| Integer(val) unless val.empty? }
262262
#
263-
# Such block shorthands for Integer, Float, Fixnum, BigDecimal, Date, Time, and DateTime
263+
# Such block shorthands for Integer, Float, BigDecimal, Date, Time, and DateTime
264264
# are currently available, but only for non-Hash declarations.
265265
#
266266
# To reference many elements, put the desired type in a literal array. e.g.:

‎lib/roxml/definition.rb‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,24 +140,19 @@ def self.fetch_bool(value, default)
140140
default
141141
end
142142
end
143-
143+
144144
CORE_BLOCK_SHORTHANDS = {
145145
# Core Shorthands
146146
Integer => lambda do |val|
147147
all(val) do |v|
148-
Integer(v) unless v.blank?
148+
v.to_i unless v.blank?
149149
end
150150
end,
151151
Float => lambda do |val|
152152
all(val) do |v|
153153
Float(v) unless v.blank?
154154
end
155155
end,
156-
Fixnum => lambda do |val|
157-
all(val) do |v|
158-
v.to_i unless v.blank?
159-
end
160-
end,
161156
Time => lambda do |val|
162157
all(val) {|v| Time.parse(v) unless v.blank? }
163158
end,

‎spec/definition_spec.rb‎

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,14 @@ def self.from_xml(val)
232232
it "should translate text to integers" do
233233
@definition.blocks.first['3'].should == 3
234234
@definition.blocks.first['792'].should == 792
235+
@definition.blocks.first['08'].should == 8
236+
@definition.blocks.first['279.23'].should == 279
235237
end
236238

237-
it "should raise on non-integer values" do
238-
proc { @definition.blocks.first['08'] }.should raise_error(ArgumentError)
239-
proc { @definition.blocks.first['793.12'] }.should raise_error(ArgumentError)
240-
proc { @definition.blocks.first['junk 11'] }.should raise_error(ArgumentError)
241-
proc { @definition.blocks.first['11sttf'] }.should raise_error(ArgumentError)
239+
it "should extract whatever is possible and fall back to 0" do
240+
@definition.blocks.first['junk 11'].should eql(0)
241+
@definition.blocks.first['.?sttf'].should eql(0)
242+
@definition.blocks.first['11sttf'].should eql(11)
242243
end
243244

244245
context "when passed an array" do
@@ -284,41 +285,17 @@ def self.from_xml(val)
284285
@definition.blocks.first['0.3'].should == BigDecimal.new("0.3")
285286
end
286287

287-
it "should extract what it can, and fall back to 0" do
288-
@definition.blocks.first['junk 11'].should eql(BigDecimal.new("0"))
289-
@definition.blocks.first['11sttf'].should eql(BigDecimal.new("11.0"))
290-
end
291-
292-
context "when passed an array" do
293-
it "should translate the array elements to integer" do
294-
@definition.blocks.first.call(["12.1", "328.2"]).should == [BigDecimal.new("12.1"), BigDecimal.new("328.2")]
295-
end
296-
end
297-
end
298-
299-
describe "Fixnum" do
300-
before do
301-
@definition = ROXML::Definition.new(:fixnumvalue, :as => Fixnum)
302-
end
303-
304-
it_should_behave_like "block shorthand type declaration"
305-
306-
it "should translate text to integers" do
307-
@definition.blocks.first['3'].should == 3
308-
@definition.blocks.first['792'].should == 792
309-
@definition.blocks.first['08'].should == 8
310-
@definition.blocks.first['279.23'].should == 279
288+
it "should raise on non-decimal values" do
289+
proc { @definition.blocks.first['junk 11'] }.should raise_error(ArgumentError)
311290
end
312291

313-
it "should extract whatever is possible and fall back to 0" do
314-
@definition.blocks.first['junk 11'].should eql(0)
315-
@definition.blocks.first['.?sttf'].should eql(0)
316-
@definition.blocks.first['11sttf'].should eql(11)
292+
it "should extract what it can" do
293+
@definition.blocks.first['11sttf'].should eql(BigDecimal.new("11.0"))
317294
end
318295

319296
context "when passed an array" do
320297
it "should translate the array elements to integer" do
321-
@definition.blocks.first.call(["792", "12", "328"]).should == [792, 12, 328]
298+
@definition.blocks.first.call(["12.1", "328.2"]).should == [BigDecimal.new("12.1"), BigDecimal.new("328.2")]
322299
end
323300
end
324301
end

‎spec/roxml_spec.rb‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,6 @@ class BookWithOctalPages
139139
@expected_pages = 239
140140
end
141141

142-
describe "with :as block shorthand" do
143-
class BookWithOctalPagesBlockShorthand
144-
include ROXML
145-
146-
xml_accessor :pages, :as => Integer, :required => true
147-
end
148-
149-
it "should apply filtering on input" do
150-
book = BookWithOctalPagesBlockShorthand.from_xml(@book_with_octal_pages_xml)
151-
book.pages.should == @expected_pages
152-
end
153-
end
154-
155142
describe "with #from_xml defined on the object" do
156143
class BookWithOctalPagesType
157144
include ROXML
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<bookwithoctalpages>
2-
<pages_with_to_xml_proc>0357</pages_with_to_xml_proc>
3-
<pages_with_type>0357</pages_with_type>
4-
</bookwithoctalpages>
2+
<pages>0357</pages>
3+
</bookwithoctalpages>

‎test/unit/definition_test.rb‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_required_conflicts_with_else
4444

4545
def test_hash_of_attrs
4646
opts = ROXML::Definition.new(:attributes, :as => {:key => '@name', :value => '@value'})
47-
assert_hash(opts, :attr => 'name', :attr => 'value')
47+
assert_hash(opts, :attr => 'value')
4848
end
4949

5050
def test_hash_with_attr_key_and_text_val
@@ -56,7 +56,7 @@ def test_hash_with_attr_key_and_text_val
5656
def test_hash_with_string_class_for_type
5757
opts = ROXML::Definition.new(:attributes, :as => {:key => 'name',
5858
:value => 'value'})
59-
assert_hash(opts, :text => 'name', :text => 'value')
59+
assert_hash(opts, :text => 'value')
6060
end
6161

6262
def test_hash_with_attr_key_and_content_val
@@ -68,7 +68,7 @@ def test_hash_with_attr_key_and_content_val
6868
def test_hash_with_options
6969
opts = ROXML::Definition.new(:definitions, :as => {:key => '@dt', :value => '@dd'},
7070
:in => :definitions, :from => 'definition')
71-
assert_hash(opts, :attr => 'dt', :attr => 'dd')
71+
assert_hash(opts, :attr => 'dd')
7272
assert_equal 'definition', opts.hash.wrapper
7373
end
7474

@@ -117,9 +117,7 @@ def test_block_shorthand_supports_bool
117117
def test_block_shorthand_supports_integer
118118
assert_equal nil, ROXML::Definition.new(:floatvalue, :as => Integer).blocks.first.call(" ")
119119
assert_equal 792, ROXML::Definition.new(:floatvalue, :as => Integer).blocks.first.call("792")
120-
assert_raise ArgumentError do
121-
ROXML::Definition.new(:floatvalue, :as => Integer).blocks.first.call("792.13")
122-
end
120+
assert_equal 792, ROXML::Definition.new(:floatvalue, :as => Integer).blocks.first.call("792.13")
123121
assert_equal [792, 12, 328], ROXML::Definition.new(:floatvalue, :as => Integer).blocks.first.call(["792", "12", "328"])
124122
end
125123

‎test/unit/to_xml_test.rb‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ def to_xml
7272
class BookWithOctalPages
7373
include ROXML
7474

75-
xml_accessor :pages_with_to_xml_proc, :as => Integer, :to_xml => proc {|val| sprintf("%#o", val) }, :required => true
76-
xml_accessor :pages_with_type, :as => OctalInteger, :required => true
75+
xml_accessor :pages, :as => OctalInteger, :required => true
7776
end
7877

7978
class TestToXmlWithOverriddenOutput < ActiveSupport::TestCase

0 commit comments

Comments
 (0)