Commit 2f20b79b8558314351421e8439bebc1313823c3a

Authored by Cyril Mougel
1 parent e3d42a62
Exists in master and in 1 other branch production

fix spec/model/notice with fabrication gem

spec/fabricators/err_fabricator.rb
@@ -10,9 +10,9 @@ Fabricator :notice do @@ -10,9 +10,9 @@ Fabricator :notice do
10 err! 10 err!
11 message 'FooError: Too Much Bar' 11 message 'FooError: Too Much Bar'
12 backtrace { random_backtrace } 12 backtrace { random_backtrace }
13 - server_environment 'environment-name' => 'production' 13 + server_environment { {'environment-name' => 'production'} }
14 request {{ 'component' => 'foo', 'action' => 'bar' }} 14 request {{ 'component' => 'foo', 'action' => 'bar' }}
15 - notifier 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com' 15 + notifier {{ 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com' }}
16 end 16 end
17 17
18 def random_backtrace 18 def random_backtrace
spec/models/notice_spec.rb
@@ -5,19 +5,19 @@ describe Notice do @@ -5,19 +5,19 @@ describe Notice do
5 5
6 context 'validations' do 6 context 'validations' do
7 it 'requires a backtrace' do 7 it 'requires a backtrace' do
8 - notice = Factory.build(:notice, :backtrace => nil) 8 + notice = Fabricate.build(:notice, :backtrace => nil)
9 notice.should_not be_valid 9 notice.should_not be_valid
10 notice.errors[:backtrace].should include("can't be blank") 10 notice.errors[:backtrace].should include("can't be blank")
11 end 11 end
12 12
13 it 'requires the server_environment' do 13 it 'requires the server_environment' do
14 - notice = Factory.build(:notice, :server_environment => nil) 14 + notice = Fabricate.build(:notice, :server_environment => nil)
15 notice.should_not be_valid 15 notice.should_not be_valid
16 notice.errors[:server_environment].should include("can't be blank") 16 notice.errors[:server_environment].should include("can't be blank")
17 end 17 end
18 18
19 it 'requires the notifier' do 19 it 'requires the notifier' do
20 - notice = Factory.build(:notice, :notifier => nil) 20 + notice = Fabricate.build(:notice, :notifier => nil)
21 notice.should_not be_valid 21 notice.should_not be_valid
22 notice.errors[:notifier].should include("can't be blank") 22 notice.errors[:notifier].should include("can't be blank")
23 end 23 end
@@ -61,8 +61,8 @@ describe Notice do @@ -61,8 +61,8 @@ describe Notice do
61 end 61 end
62 [:server_environment, :request, :notifier].each do |key| 62 [:server_environment, :request, :notifier].each do |key|
63 it "replaces . with . and $ with $ in keys used in #{key}" do 63 it "replaces . with . and $ with $ in keys used in #{key}" do
64 - err = Factory(:err)  
65 - notice = Factory(:notice, :err => err, key => @hash) 64 + err = Fabricate(:err)
  65 + notice = Fabricate(:notice, :err => err, key => @hash)
66 notice.send(key).should == @hash_sanitized 66 notice.send(key).should == @hash_sanitized
67 end 67 end
68 end 68 end
@@ -71,42 +71,42 @@ describe Notice do @@ -71,42 +71,42 @@ describe Notice do
71 71
72 describe "user agent" do 72 describe "user agent" do
73 it "should be parsed and human-readable" do 73 it "should be parsed and human-readable" do
74 - notice = Factory.build(:notice, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}}) 74 + notice = Fabricate.build(:notice, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}})
75 notice.user_agent.browser.should == 'Chrome' 75 notice.user_agent.browser.should == 'Chrome'
76 notice.user_agent.version.to_s.should =~ /^10\.0/ 76 notice.user_agent.version.to_s.should =~ /^10\.0/
77 end 77 end
78 78
79 it "should be nil if HTTP_USER_AGENT is blank" do 79 it "should be nil if HTTP_USER_AGENT is blank" do
80 - notice = Factory.build(:notice) 80 + notice = Fabricate.build(:notice)
81 notice.user_agent.should == nil 81 notice.user_agent.should == nil
82 end 82 end
83 end 83 end
84 84
85 describe "user agent string" do 85 describe "user agent string" do
86 it "should be parsed and human-readable" do 86 it "should be parsed and human-readable" do
87 - notice = Factory.build(:notice, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}}) 87 + notice = Fabricate.build(:notice, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}})
88 notice.user_agent_string.should == 'Chrome 10.0.648.204' 88 notice.user_agent_string.should == 'Chrome 10.0.648.204'
89 end 89 end
90 90
91 it "should be nil if HTTP_USER_AGENT is blank" do 91 it "should be nil if HTTP_USER_AGENT is blank" do
92 - notice = Factory.build(:notice) 92 + notice = Fabricate.build(:notice)
93 notice.user_agent_string.should == "N/A" 93 notice.user_agent_string.should == "N/A"
94 end 94 end
95 end 95 end
96 96
97 describe "host" do 97 describe "host" do
98 it "returns host if url is valid" do 98 it "returns host if url is valid" do
99 - notice = Factory.build(:notice, :request => {'url' => "http://example.com/resource/12"}) 99 + notice = Fabricate.build(:notice, :request => {'url' => "http://example.com/resource/12"})
100 notice.host.should == 'example.com' 100 notice.host.should == 'example.com'
101 end 101 end
102 - 102 +
103 it "returns 'N/A' when url is not valid" do 103 it "returns 'N/A' when url is not valid" do
104 - notice = Factory.build(:notice, :request => {'url' => "some string"}) 104 + notice = Fabricate.build(:notice, :request => {'url' => "some string"})
105 notice.host.should == 'N/A' 105 notice.host.should == 'N/A'
106 end 106 end
107 107
108 it "returns 'N/A' when url is empty" do 108 it "returns 'N/A' when url is empty" do
109 - notice = Factory.build(:notice, :request => {}) 109 + notice = Fabricate.build(:notice, :request => {})
110 notice.host.should == 'N/A' 110 notice.host.should == 'N/A'
111 end 111 end
112 112
@@ -118,8 +118,8 @@ describe Notice do @@ -118,8 +118,8 @@ describe Notice do
118 118
119 before do 119 before do
120 Errbit::Config.per_app_email_at_notices = true 120 Errbit::Config.per_app_email_at_notices = true
121 - @app = Factory(:app_with_watcher, :email_at_notices => custom_thresholds)  
122 - @err = Factory(:err, :problem => Factory(:problem, :app => @app)) 121 + @app = Fabricate(:app_with_watcher, :email_at_notices => custom_thresholds)
  122 + @err = Fabricate(:err, :problem => Fabricate(:problem, :app => @app))
123 end 123 end
124 124
125 after do 125 after do
@@ -131,7 +131,7 @@ describe Notice do @@ -131,7 +131,7 @@ describe Notice do
131 @err.problem.stub(:notices_count).and_return(threshold) 131 @err.problem.stub(:notices_count).and_return(threshold)
132 Mailer.should_receive(:err_notification). 132 Mailer.should_receive(:err_notification).
133 and_return(mock('email', :deliver => true)) 133 and_return(mock('email', :deliver => true))
134 - Factory(:notice, :err => @err) 134 + Fabricate(:notice, :err => @err)
135 end 135 end
136 end 136 end
137 end 137 end
@@ -140,8 +140,8 @@ describe Notice do @@ -140,8 +140,8 @@ describe Notice do
140 140
141 before do 141 before do
142 Errbit::Config.per_app_email_at_notices = true 142 Errbit::Config.per_app_email_at_notices = true
143 - @app = Factory(:app_with_watcher, :email_at_notices => [1])  
144 - @err = Factory(:err, :problem => Factory(:problem, :app => @app, :notices_count => 100)) 143 + @app = Fabricate(:app_with_watcher, :email_at_notices => [1])
  144 + @err = Fabricate(:err, :problem => Fabricate(:problem, :app => @app, :notices_count => 100))
145 end 145 end
146 146
147 after do 147 after do
@@ -152,7 +152,7 @@ describe Notice do @@ -152,7 +152,7 @@ describe Notice do
152 @err.problem.resolve! 152 @err.problem.resolve!
153 Mailer.should_receive(:err_notification). 153 Mailer.should_receive(:err_notification).
154 and_return(mock('email', :deliver => true)) 154 and_return(mock('email', :deliver => true))
155 - Factory(:notice, :err => @err) 155 + Fabricate(:notice, :err => @err)
156 end 156 end
157 end 157 end
158 end 158 end