This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 164
/
application_spec.rb
83 lines (81 loc) · 2.86 KB
/
application_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
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Using the Application Model", :reset_redis => true do
before(:all) do
@appdata1 = {:name => "my_application"}
@appdata2 = {:name => "my_other_app"}
@appconf_string = {:name => "mystringconf", :format => "string", :body => "some_var"}
@appconf_json = {:name => "myjsonconf", :format => "json", :body => @appconf_string.to_json}
end
before(:each) do
Ohm.redis.flushdb
end
after(:each) do
Ohm.redis.flushdb
end
describe "should" do
it "create a new Noah::Application" do
a = Noah::Application.create(@appdata1)
a.valid?.should == true
a.is_new?.should == true
b = Noah::Application.find(@appdata1).first
b.should == a
end
it "create a new Noah::Application with Configurations" do
a = Noah::Application.create(@appdata1)
a.configurations << Noah::Configuration.create(@appconf_string)
a.valid?.should == true
a.is_new?.should == true
a.save
b = Noah::Application.find(@appdata1).first
b.should == a
b.configurations.size.should == 1
b.configurations.first.name.should == @appconf_string[:name]
b.configurations.first.format.should == @appconf_string[:format]
b.configurations.first.body.should == @appconf_string[:body]
end
it "create a new Noah::Application via find_or_create" do
a = Noah::Application.find_or_create(@appdata2)
a.valid?.should == true
a.is_new?.should == true
b = Noah::Application.find(@appdata2).first
b.should == a
end
it "update an existing Noah::Application via find_or_create" do
a = Noah::Application.create(@appdata1)
a.is_new?.should == true
sleep 2
b = Noah::Application.find_or_create(@appdata1)
b.is_new?.should == false
end
it "delete an existing Noah::Application" do
a = Noah::Application.create(@appdata1)
b = Noah::Application.find(@appdata1).first
b.should == a
b.delete
c = Noah::Application.find(@appdata1).first
c.nil?.should == true
end
it "return all Noah::Applications" do
a = Noah::Application.create(@appdata1)
b = Noah::Application.create(@appdata2)
c = Noah::Applications.all
c.size.should == 2
c.keys.member?(a.name).should == true
c.keys.member?(b.name).should == true
end
end
describe "should not" do
it "should not create a new Noah::Application without a name" do
a = Noah::Application.create
a.valid?.should == false
a.errors.should == [[:name, :not_present]]
end
# it "should not create a duplicate Noah::Application" do
# a = Noah::Application.create(@appdata1)
# a.valid?.should == true
# b = Noah::Application.create(@appdata1)
# b.valid?.should == false
# b.errors.should == [[:name, :not_unique]]
# end
end
end