File tree 4 files changed +29
-11
lines changed
4 files changed +29
-11
lines changed Original file line number Diff line number Diff line change 1
1
## edge
2
2
3
+ * ` Element#[] ` and ` Element#attr ` now return ` nil ` for empty attributes,
4
+ instead of returning an empty string.
5
+
3
6
* Add ` HTTP.setup ` and ` HTTP.setup= ` to access ` $.ajaxSetup `
4
7
5
8
* Add PATCH and HEAD support to ` HTTP `
Original file line number Diff line number Diff line change 1
1
source 'https://rubygems.org'
2
2
gemspec
3
3
4
- gem 'opal' , github : 'opal/opal'
5
- # gem 'opal', path : '.. /opal'
4
+ gem 'opal' , github : 'opal/opal'
5
+ gem 'opal-rspec ' , github : 'opal /opal-rspec '
Original file line number Diff line number Diff line change @@ -90,14 +90,18 @@ def to_n
90
90
end
91
91
92
92
def []( name )
93
- `self.attr(name) || "" `
93
+ `self.attr(name) || nil `
94
94
end
95
95
96
- def add_attribute name
97
- self [ name ] = ''
96
+ def attr ( name , value = nil )
97
+ if value . nil?
98
+ `self.attr(name) || nil`
99
+ else
100
+ `self.attr(name, value)`
101
+ end
98
102
end
99
103
100
- def has_attribute? name
104
+ def has_attribute? ( name )
101
105
`!!self.attr(name)`
102
106
end
103
107
Original file line number Diff line number Diff line change 45
45
Element . find ( '#attr-foo' ) [ :title ] . should == "Hello there!"
46
46
end
47
47
48
- it 'should return an empty string for an empty attribute value' do
49
- Element . find ( '#attr-bar' ) [ :title ] . should == ""
50
- Element . find ( '#attr-baz' ) [ :title ] . should == ""
48
+ it 'should return nil for an empty attribute' do
49
+ expect ( Element . find ( '#attr-bar' ) [ :title ] ) . to be_nil
50
+ expect ( Element . find ( '#attr-baz' ) [ :title ] ) . to be_nil
51
+ end
52
+ end
53
+
54
+ describe '#attr' do
55
+ it 'returns attributes from elements' do
56
+ expect ( Element . find ( '#attr-foo' ) . attr ( :title ) ) . to eq ( 'Hello there!' )
57
+ end
58
+
59
+ it 'returns nil for empty attributes' do
60
+ expect ( Element . find ( '#attr-bar' ) . attr ( :title ) ) . to be_nil
61
+ expect ( Element . find ( '#attr-baz' ) . attr ( :title ) ) . to be_nil
51
62
end
52
63
end
53
64
54
65
describe '#[]=' do
55
66
it 'should set the attr value on the element' do
56
67
woosh = Element . find '#attr-woosh'
57
- woosh [ :title ] . should == ""
68
+ expect ( woosh [ :title ] ) . to be_nil
58
69
59
70
woosh [ :title ] = "Oranges"
60
- woosh [ :title ] . should == " Oranges"
71
+ expect ( woosh [ :title ] ) . to eq ( ' Oranges' )
61
72
end
62
73
63
74
it 'should replace the old value for the attribute' do
You can’t perform that action at this time.
0 commit comments