mhennemeyer-rwriteboard 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rwriteboard.rb +3 -2
- data/rwriteboard.gemspec +1 -1
- data/spec/rwriteboard_spec.rb +34 -0
- metadata +1 -1
data/lib/rwriteboard.rb
CHANGED
@@ -19,7 +19,7 @@ class Writeboard
|
|
19
19
|
def @@writeboards.find(hash)
|
20
20
|
memo = self
|
21
21
|
hash.each do |k,v|
|
22
|
-
memo = [memo.detect {|wb| wb.send(k.to_sym) == v}]
|
22
|
+
memo = [memo.detect {|wb| !wb.nil? && wb.respond_to?(k.to_sym) && wb.send(k.to_sym) == v}]
|
23
23
|
end
|
24
24
|
memo.first
|
25
25
|
end
|
@@ -28,6 +28,8 @@ class Writeboard
|
|
28
28
|
self.password = hash[:password]
|
29
29
|
self.path = hash[:path]
|
30
30
|
self.name = hash[:name]
|
31
|
+
@@writeboards << self
|
32
|
+
self
|
31
33
|
end
|
32
34
|
|
33
35
|
def get
|
@@ -71,7 +73,6 @@ class Writeboard
|
|
71
73
|
path = "/" + path unless path =~ /^\//
|
72
74
|
name = hash[:name] || self.count + 1
|
73
75
|
wb = self.new(:password => password, :path => path, :name => name)
|
74
|
-
@@writeboards << wb
|
75
76
|
if block_given?
|
76
77
|
wb.logged_in do |_wb|
|
77
78
|
yield _wb
|
data/rwriteboard.gemspec
CHANGED
data/spec/rwriteboard_spec.rb
CHANGED
@@ -31,6 +31,40 @@ describe Writeboard do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
describe "writeboards.find(hash)" do
|
35
|
+
describe "| returns the first writeboard that matches all conditions defined by name value pairs in the arg hash | " do
|
36
|
+
describe "@@writeboards empty" do
|
37
|
+
it "should return nil if @@writeboards is empty" do
|
38
|
+
Writeboard.writeboards.find(:name => "value").should be_nil
|
39
|
+
end
|
40
|
+
it "should return nil if hash contains several names and collection is empty" do
|
41
|
+
Writeboard.writeboards.find(:nonexistant => "nonexistant", :anotherone => "value").should be_nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
describe "@@writeboards contains a writeboard" do
|
45
|
+
before(:each) do
|
46
|
+
@writeboard = Writeboard.new({:name => "value", :password => "123456", :path => "/path"})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return existing remote_feature with name value" do
|
50
|
+
Writeboard.writeboards.find(:name => "value").should eql(@writeboard)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return nil if hash contains value that doesn't match remote_feature" do
|
54
|
+
Writeboard.writeboards.find(:name => "nonexistant").should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return nil if hash contains name pair that doesn't match remote_feature" do
|
58
|
+
Writeboard.writeboards.find(:nonexistant => "nonexistant").should be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return nil if hash contains several names that doesn't match remote_feature" do
|
62
|
+
Writeboard.writeboards.find(:nonexistant => "nonexistant", :anotherone => "value").should be_nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
34
68
|
describe ".find(hash)" do
|
35
69
|
it "should yield the writeboard, identified by hash and logged in" do
|
36
70
|
Writeboard.find :name => "Feature1" do |wb|
|