Skip to content

Commit b62bf81

Browse files
author
Timo Sand
committed
Fixed initialisation and added tests
1 parent d6811ed commit b62bf81

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/netvisor/element_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def self.included(base)
33
base.class_exec do
44
def initialize(args = {})
55
args.each_pair do |key, val|
6-
self.send("#{key}=", val) if ElementBase.method_defined? key
6+
self.send("#{key}=", val) if self.class.method_defined? key
77
end
88
end
99
end

spec/netvisor/element_base_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require "spec_helper"
2+
3+
module Netvisor
4+
5+
class Dummy
6+
include HappyMapper
7+
include ElementBase
8+
9+
attribute :foo, String
10+
element :bar, String
11+
end
12+
13+
describe ElementBase do
14+
describe "#initialize" do
15+
it "Class values are nil on no parameters" do
16+
dummy = Dummy.new
17+
expect(dummy.foo).to be_nil
18+
expect(dummy.bar).to be_nil
19+
end
20+
21+
it "Class attribute is set to specified value" do
22+
dummy = Dummy.new(:foo => 'foo')
23+
expect(dummy.foo).to eq 'foo'
24+
expect(dummy.bar).to be_nil
25+
end
26+
end
27+
end
28+
end

0 commit comments

Comments
 (0)