This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
/
configuration_spec.rb
89 lines (85 loc) · 3.28 KB
/
configuration_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Using the Configuration Model", :reset_redis => true do
before(:each) do
Ohm.redis.flushdb
app = Noah::Application.create :name => "my_application"
@appconf_string = {:name => "mystringconf", :format => "string", :body => "some_var", :application_id => app.id}
@appconf_json = {:name => "myjsonconf", :format => "json", :body => @appconf_string.to_json, :application_id => app.id}
@appconf_missing_name = @appconf_string.reject {|k, v| k == :name}
@appconf_missing_format = @appconf_string.reject {|k, v| k == :format}
@appconf_missing_body = @appconf_string.reject {|k, v| k == :body}
@appconf_missing_application = @appconf_string.reject {|k, v| k == :application_id}
end
after(:each) do
Ohm.redis.flushdb
end
describe "should" do
it "create a new Configuration" do
c = Noah::Configuration.create(@appconf_string)
c.valid?.should == true
c.is_new?.should == true
b = Noah::Configuration[c.id]
b.should == c
end
it "create a new Configuration via find_or_create" do
c = Noah::Configuration.find_or_create(@appconf_string)
c.valid?.should == true
c.is_new?.should == true
a = Noah::Configuration[c.id]
a.should == c
end
it "update an existing Configuration via find_or_create" do
c = Noah::Configuration.find_or_create(@appconf_string)
c.valid?.should == true
c.is_new?.should == true
sleep(3)
c.body = "some_other_var"
c.save
c.body.should == "some_other_var"
c.is_new?.should == false
end
it "delete an existing Configuration" do
a = Noah::Configuration.find_or_create(@appconf_string)
b = Noah::Configuration.find(@appconf_string).first
b.should == a
a.delete
c = Noah::Configuration.find(@appconf_string).first
c.nil?.should == true
end
it "return all Configurations" do
a = Noah::Configuration.find_or_create(@appconf_string)
b = Noah::Configuration.find_or_create(@appconf_json)
c = Noah::Configurations.all
c.size.should == 2
c.member?(a).should == true
c.member?(b).should == true
end
end
describe "should not" do
it "create a new Configuration without a name" do
a = Noah::Configuration.create(@appconf_missing_name)
a.valid?.should == false
a.errors.should == [[:name, :not_present]]
end
it "create a new Configuration without a format" do
a = Noah::Configuration.create(@appconf_missing_format)
a.valid?.should == false
a.errors.should == [[:format, :not_present]]
end
it "create a new Configuration without a body" do
a = Noah::Configuration.create(@appconf_missing_body)
a.valid?.should == false
a.errors.should == [[:body, :not_present]]
end
it "create a new Confguration without an application" do
a = Noah::Configuration.create(@appconf_missing_application)
a.valid?.should == false
a.errors.should == [[:application_id, :not_present]]
end
it "create a duplicate Configuration" do
a = Noah::Configuration.create(@appconf_string)
b = Noah::Configuration.create(@appconf_string)
b.errors.should == [[[:name, :application_id], :not_unique]]
end
end
end