Commit 2f20b79b8558314351421e8439bebc1313823c3a
1 parent
e3d42a62
Exists in
master
and in
1 other branch
fix spec/model/notice with fabrication gem
Showing
2 changed files
with
21 additions
and
21 deletions
Show diff stats
spec/fabricators/err_fabricator.rb
... | ... | @@ -10,9 +10,9 @@ Fabricator :notice do |
10 | 10 | err! |
11 | 11 | message 'FooError: Too Much Bar' |
12 | 12 | backtrace { random_backtrace } |
13 | - server_environment 'environment-name' => 'production' | |
13 | + server_environment { {'environment-name' => 'production'} } | |
14 | 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 | 16 | end |
17 | 17 | |
18 | 18 | def random_backtrace | ... | ... |
spec/models/notice_spec.rb
... | ... | @@ -5,19 +5,19 @@ describe Notice do |
5 | 5 | |
6 | 6 | context 'validations' do |
7 | 7 | it 'requires a backtrace' do |
8 | - notice = Factory.build(:notice, :backtrace => nil) | |
8 | + notice = Fabricate.build(:notice, :backtrace => nil) | |
9 | 9 | notice.should_not be_valid |
10 | 10 | notice.errors[:backtrace].should include("can't be blank") |
11 | 11 | end |
12 | 12 | |
13 | 13 | it 'requires the server_environment' do |
14 | - notice = Factory.build(:notice, :server_environment => nil) | |
14 | + notice = Fabricate.build(:notice, :server_environment => nil) | |
15 | 15 | notice.should_not be_valid |
16 | 16 | notice.errors[:server_environment].should include("can't be blank") |
17 | 17 | end |
18 | 18 | |
19 | 19 | it 'requires the notifier' do |
20 | - notice = Factory.build(:notice, :notifier => nil) | |
20 | + notice = Fabricate.build(:notice, :notifier => nil) | |
21 | 21 | notice.should_not be_valid |
22 | 22 | notice.errors[:notifier].should include("can't be blank") |
23 | 23 | end |
... | ... | @@ -61,8 +61,8 @@ describe Notice do |
61 | 61 | end |
62 | 62 | [:server_environment, :request, :notifier].each do |key| |
63 | 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 | 66 | notice.send(key).should == @hash_sanitized |
67 | 67 | end |
68 | 68 | end |
... | ... | @@ -71,42 +71,42 @@ describe Notice do |
71 | 71 | |
72 | 72 | describe "user agent" do |
73 | 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 | 75 | notice.user_agent.browser.should == 'Chrome' |
76 | 76 | notice.user_agent.version.to_s.should =~ /^10\.0/ |
77 | 77 | end |
78 | 78 | |
79 | 79 | it "should be nil if HTTP_USER_AGENT is blank" do |
80 | - notice = Factory.build(:notice) | |
80 | + notice = Fabricate.build(:notice) | |
81 | 81 | notice.user_agent.should == nil |
82 | 82 | end |
83 | 83 | end |
84 | 84 | |
85 | 85 | describe "user agent string" do |
86 | 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 | 88 | notice.user_agent_string.should == 'Chrome 10.0.648.204' |
89 | 89 | end |
90 | 90 | |
91 | 91 | it "should be nil if HTTP_USER_AGENT is blank" do |
92 | - notice = Factory.build(:notice) | |
92 | + notice = Fabricate.build(:notice) | |
93 | 93 | notice.user_agent_string.should == "N/A" |
94 | 94 | end |
95 | 95 | end |
96 | 96 | |
97 | 97 | describe "host" do |
98 | 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 | 100 | notice.host.should == 'example.com' |
101 | 101 | end |
102 | - | |
102 | + | |
103 | 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 | 105 | notice.host.should == 'N/A' |
106 | 106 | end |
107 | 107 | |
108 | 108 | it "returns 'N/A' when url is empty" do |
109 | - notice = Factory.build(:notice, :request => {}) | |
109 | + notice = Fabricate.build(:notice, :request => {}) | |
110 | 110 | notice.host.should == 'N/A' |
111 | 111 | end |
112 | 112 | |
... | ... | @@ -118,8 +118,8 @@ describe Notice do |
118 | 118 | |
119 | 119 | before do |
120 | 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 | 123 | end |
124 | 124 | |
125 | 125 | after do |
... | ... | @@ -131,7 +131,7 @@ describe Notice do |
131 | 131 | @err.problem.stub(:notices_count).and_return(threshold) |
132 | 132 | Mailer.should_receive(:err_notification). |
133 | 133 | and_return(mock('email', :deliver => true)) |
134 | - Factory(:notice, :err => @err) | |
134 | + Fabricate(:notice, :err => @err) | |
135 | 135 | end |
136 | 136 | end |
137 | 137 | end |
... | ... | @@ -140,8 +140,8 @@ describe Notice do |
140 | 140 | |
141 | 141 | before do |
142 | 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 | 145 | end |
146 | 146 | |
147 | 147 | after do |
... | ... | @@ -152,7 +152,7 @@ describe Notice do |
152 | 152 | @err.problem.resolve! |
153 | 153 | Mailer.should_receive(:err_notification). |
154 | 154 | and_return(mock('email', :deliver => true)) |
155 | - Factory(:notice, :err => @err) | |
155 | + Fabricate(:notice, :err => @err) | |
156 | 156 | end |
157 | 157 | end |
158 | 158 | end | ... | ... |