Commit 99752a49250db4d44a6dfe1f767051a0ca70e9b0

Authored by Cyril Mougel
2 parents d9438486 4b00b576
Exists in master and in 1 other branch production

Merge pull request #515 from arthurnn/mongoid_upgrade

Conflicts:
	app/models/notice.rb
@@ -4,16 +4,12 @@ env: @@ -4,16 +4,12 @@ env:
4 rvm: 4 rvm:
5 - 2.0.0 5 - 2.0.0
6 - 1.9.3 6 - 1.9.3
7 - - 1.9.2  
8 - - 1.8.7  
9 - rbx-19mode 7 - rbx-19mode
10 - - rbx-18mode  
11 services: mongodb 8 services: mongodb
12 #script: ./script/rspec-queue-mongoid.rb --format progress spec 9 #script: ./script/rspec-queue-mongoid.rb --format progress spec
13 matrix: 10 matrix:
14 allow_failures: 11 allow_failures:
15 - rvm: rbx-19mode 12 - rvm: rbx-19mode
16 - - rvm: rbx-18mode  
17 13
18 # To stop Travis from running tests for a new commit, 14 # To stop Travis from running tests for a new commit,
19 # add the following to your commit message: [ci skip] 15 # add the following to your commit message: [ci skip]
1 source 'http://rubygems.org' 1 source 'http://rubygems.org'
2 2
3 gem 'rails', '3.2.13' 3 gem 'rails', '3.2.13'
4 -gem 'mongoid', '~> 2.7.1' 4 +gem 'mongoid', '~> 3.1.4'
5 5
6 -# Mongoid rails migration > 0.0.14 is not compatible to Mongoid 2.x  
7 -gem 'mongoid_rails_migrations', '~> 0.0.14'  
8 -gem 'devise', '~> 2.2.6' # Last version supporting ruby 1.8.7 6 +gem 'mongoid_rails_migrations', '~> 1.0.1'
  7 +gem 'devise'
9 gem 'haml' 8 gem 'haml'
10 gem 'htmlentities' 9 gem 'htmlentities'
11 gem 'rack-ssl', :require => 'rack/ssl' # force SSL 10 gem 'rack-ssl', :require => 'rack/ssl' # force SSL
@@ -75,13 +74,6 @@ gem 'flowdock' @@ -75,13 +74,6 @@ gem 'flowdock'
75 # GitHub OAuth 74 # GitHub OAuth
76 gem 'omniauth-github' 75 gem 'omniauth-github'
77 76
78 -  
79 -platform :ruby do  
80 - gem 'mongo'  
81 - gem 'bson'  
82 - gem 'bson_ext'  
83 -end  
84 -  
85 gem 'ri_cal' 77 gem 'ri_cal'
86 gem 'yajl-ruby', :require => "yajl" 78 gem 'yajl-ruby', :require => "yajl"
87 79
1 GIT 1 GIT
2 remote: https://github.com/NARKOZ/gitlab.git 2 remote: https://github.com/NARKOZ/gitlab.git
3 - revision: 53d7a8a86dfed63e56eeb16ea496bb7a82de337e 3 + revision: 7a00d38c53335010d2fb8a233247fe2c97338903
4 specs: 4 specs:
5 gitlab (2.2.0) 5 gitlab (2.2.0)
6 httparty 6 httparty
@@ -41,8 +41,7 @@ GEM @@ -41,8 +41,7 @@ GEM
41 i18n (= 0.6.1) 41 i18n (= 0.6.1)
42 multi_json (~> 1.0) 42 multi_json (~> 1.0)
43 addressable (2.3.5) 43 addressable (2.3.5)
44 - airbrake (3.1.12)  
45 - activesupport 44 + airbrake (3.1.13)
46 builder 45 builder
47 json 46 json
48 arel (3.0.2) 47 arel (3.0.2)
@@ -59,9 +58,6 @@ GEM @@ -59,9 +58,6 @@ GEM
59 multi_json (~> 1.3) 58 multi_json (~> 1.3)
60 nokogiri (~> 1.5.2) 59 nokogiri (~> 1.5.2)
61 simple_oauth 60 simple_oauth
62 - bson (1.8.6)  
63 - bson_ext (1.8.6)  
64 - bson (~> 1.8.6)  
65 builder (3.0.4) 61 builder (3.0.4)
66 callsite (0.0.11) 62 callsite (0.0.11)
67 campy (0.1.3) 63 campy (0.1.3)
@@ -104,7 +100,7 @@ GEM @@ -104,7 +100,7 @@ GEM
104 debugger-linecache (1.2.0) 100 debugger-linecache (1.2.0)
105 debugger-ruby_core_source (1.2.3) 101 debugger-ruby_core_source (1.2.3)
106 decent_exposure (2.2.1) 102 decent_exposure (2.2.1)
107 - devise (2.2.6) 103 + devise (2.2.7)
108 bcrypt-ruby (~> 3.0) 104 bcrypt-ruby (~> 3.0)
109 orm_adapter (~> 0.1) 105 orm_adapter (~> 0.1)
110 railties (~> 3.1) 106 railties (~> 3.1)
@@ -137,7 +133,7 @@ GEM @@ -137,7 +133,7 @@ GEM
137 hashie (1.2.0) 133 hashie (1.2.0)
138 highline (1.6.19) 134 highline (1.6.19)
139 hike (1.2.3) 135 hike (1.2.3)
140 - hipchat (0.10.0) 136 + hipchat (0.11.0)
141 httparty 137 httparty
142 hoi (0.0.6) 138 hoi (0.0.6)
143 httparty (> 0.6.0) 139 httparty (> 0.6.0)
@@ -168,8 +164,8 @@ GEM @@ -168,8 +164,8 @@ GEM
168 kgio (2.8.0) 164 kgio (2.8.0)
169 launchy (2.3.0) 165 launchy (2.3.0)
170 addressable (~> 2.3) 166 addressable (~> 2.3)
171 - libv8 (3.11.8.17)  
172 - libxml-ruby (2.6.0) 167 + libv8 (3.16.14.3)
  168 + libxml-ruby (2.7.0)
173 lighthouse-api (2.0) 169 lighthouse-api (2.0)
174 activeresource (>= 3.0.0) 170 activeresource (>= 3.0.0)
175 activesupport (>= 3.0.0) 171 activesupport (>= 3.0.0)
@@ -178,24 +174,24 @@ GEM @@ -178,24 +174,24 @@ GEM
178 mail (2.5.4) 174 mail (2.5.4)
179 mime-types (~> 1.16) 175 mime-types (~> 1.16)
180 treetop (~> 1.4.8) 176 treetop (~> 1.4.8)
181 - meta_request (0.2.7) 177 + meta_request (0.2.8)
182 callsite 178 callsite
183 rack-contrib 179 rack-contrib
184 railties 180 railties
185 method_source (0.8.2) 181 method_source (0.8.2)
186 - mime-types (1.23)  
187 - mongo (1.8.6)  
188 - bson (~> 1.8.6)  
189 - mongoid (2.7.1)  
190 - activemodel (~> 3.1)  
191 - mongo (~> 1.8) 182 + mime-types (1.24)
  183 + mongoid (3.1.4)
  184 + activemodel (~> 3.2)
  185 + moped (~> 1.4)
  186 + origin (~> 1.0)
192 tzinfo (~> 0.3.22) 187 tzinfo (~> 0.3.22)
193 - mongoid_rails_migrations (0.0.14)  
194 - activesupport (>= 3.0.0) 188 + mongoid_rails_migrations (1.0.1)
  189 + activesupport (>= 3.2.0)
195 bundler (>= 1.0.0) 190 bundler (>= 1.0.0)
196 - rails (>= 3.0.0)  
197 - railties (>= 3.0.0)  
198 - multi_json (1.7.8) 191 + rails (>= 3.2.0)
  192 + railties (>= 3.2.0)
  193 + moped (1.5.1)
  194 + multi_json (1.7.9)
199 multi_xml (0.5.5) 195 multi_xml (0.5.5)
200 multipart-post (1.2.0) 196 multipart-post (1.2.0)
201 net-scp (1.1.2) 197 net-scp (1.1.2)
@@ -230,19 +226,18 @@ GEM @@ -230,19 +226,18 @@ GEM
230 omniauth-oauth2 (1.1.1) 226 omniauth-oauth2 (1.1.1)
231 oauth2 (~> 0.8.0) 227 oauth2 (~> 0.8.0)
232 omniauth (~> 1.0) 228 omniauth (~> 1.0)
  229 + origin (1.1.0)
233 orm_adapter (0.4.0) 230 orm_adapter (0.4.0)
234 oruen_redmine_client (0.0.1) 231 oruen_redmine_client (0.0.1)
235 activeresource (>= 2.3.0) 232 activeresource (>= 2.3.0)
236 pivotal-tracker (0.5.10) 233 pivotal-tracker (0.5.10)
237 builder 234 builder
238 - builder  
239 crack 235 crack
240 happymapper (>= 0.3.2) 236 happymapper (>= 0.3.2)
241 nokogiri (>= 1.4.3) 237 nokogiri (>= 1.4.3)
242 nokogiri (>= 1.5.5) 238 nokogiri (>= 1.5.5)
243 nokogiri-happymapper (>= 0.5.4) 239 nokogiri-happymapper (>= 0.5.4)
244 rest-client (~> 1.6.0) 240 rest-client (~> 1.6.0)
245 - rest-client (~> 1.6.0)  
246 pjax_rails (0.3.4) 241 pjax_rails (0.3.4)
247 jquery-rails 242 jquery-rails
248 polyglot (0.3.3) 243 polyglot (0.3.3)
@@ -293,8 +288,8 @@ GEM @@ -293,8 +288,8 @@ GEM
293 rest-client (1.6.7) 288 rest-client (1.6.7)
294 mime-types (>= 1.16) 289 mime-types (>= 1.16)
295 ri_cal (0.8.8) 290 ri_cal (0.8.8)
296 - rspec-core (2.14.4)  
297 - rspec-expectations (2.14.1) 291 + rspec-core (2.14.5)
  292 + rspec-expectations (2.14.2)
298 diff-lcs (>= 1.1.3, < 2.0) 293 diff-lcs (>= 1.1.3, < 2.0)
299 rspec-mocks (2.14.3) 294 rspec-mocks (2.14.3)
300 rspec-rails (2.14.0) 295 rspec-rails (2.14.0)
@@ -316,7 +311,7 @@ GEM @@ -316,7 +311,7 @@ GEM
316 json 311 json
317 rest-client 312 rest-client
318 safe_yaml (0.9.5) 313 safe_yaml (0.9.5)
319 - selenium-webdriver (2.34.0) 314 + selenium-webdriver (2.35.0)
320 childprocess (>= 0.2.5) 315 childprocess (>= 0.2.5)
321 multi_json (~> 1.0) 316 multi_json (~> 1.0)
322 rubyzip 317 rubyzip
@@ -343,8 +338,8 @@ GEM @@ -343,8 +338,8 @@ GEM
343 taskmapper-unfuddle (0.7.0) 338 taskmapper-unfuddle (0.7.0)
344 addressable (~> 2.2) 339 addressable (~> 2.2)
345 taskmapper (~> 0.8) 340 taskmapper (~> 0.8)
346 - therubyracer (0.11.4)  
347 - libv8 (~> 3.11.8.12) 341 + therubyracer (0.12.0)
  342 + libv8 (~> 3.16.14.0)
348 ref 343 ref
349 thin (1.5.1) 344 thin (1.5.1)
350 daemons (>= 1.0.9) 345 daemons (>= 1.0.9)
@@ -353,10 +348,10 @@ GEM @@ -353,10 +348,10 @@ GEM
353 thor (0.18.1) 348 thor (0.18.1)
354 tilt (1.4.1) 349 tilt (1.4.1)
355 timecop (0.6.1) 350 timecop (0.6.1)
356 - treetop (1.4.14) 351 + treetop (1.4.15)
357 polyglot 352 polyglot
358 polyglot (>= 0.3.1) 353 polyglot (>= 0.3.1)
359 - turbo-sprockets-rails3 (0.3.6) 354 + turbo-sprockets-rails3 (0.3.9)
360 railties (> 3.2.8, < 4.0.0) 355 railties (> 3.2.8, < 4.0.0)
361 sprockets (>= 2.0.0) 356 sprockets (>= 2.0.0)
362 tzinfo (0.3.37) 357 tzinfo (0.3.37)
@@ -390,8 +385,6 @@ DEPENDENCIES @@ -390,8 +385,6 @@ DEPENDENCIES
390 better_errors 385 better_errors
391 binding_of_caller 386 binding_of_caller
392 bitbucket_rest_api 387 bitbucket_rest_api
393 - bson  
394 - bson_ext  
395 campy (= 0.1.3) 388 campy (= 0.1.3)
396 capistrano 389 capistrano
397 capybara (~> 2.0.1) 390 capybara (~> 2.0.1)
@@ -399,7 +392,7 @@ DEPENDENCIES @@ -399,7 +392,7 @@ DEPENDENCIES
399 database_cleaner (~> 0.9.0) 392 database_cleaner (~> 0.9.0)
400 debugger 393 debugger
401 decent_exposure 394 decent_exposure
402 - devise (~> 2.2.6) 395 + devise
403 email_spec 396 email_spec
404 execjs 397 execjs
405 fabrication (~> 1.3.0) 398 fabrication (~> 1.3.0)
@@ -418,9 +411,8 @@ DEPENDENCIES @@ -418,9 +411,8 @@ DEPENDENCIES
418 launchy 411 launchy
419 lighthouse-api 412 lighthouse-api
420 meta_request 413 meta_request
421 - mongo  
422 - mongoid (~> 2.7.1)  
423 - mongoid_rails_migrations (~> 0.0.14) 414 + mongoid (~> 3.1.4)
  415 + mongoid_rails_migrations (~> 1.0.1)
424 octokit 416 octokit
425 omniauth-github 417 omniauth-github
426 oruen_redmine_client 418 oruen_redmine_client
app/controllers/api/v1/notices_controller.rb
@@ -11,7 +11,9 @@ class Api::V1::NoticesController &lt; ApplicationController @@ -11,7 +11,9 @@ class Api::V1::NoticesController &lt; ApplicationController
11 query = {:created_at => {"$lte" => end_date, "$gte" => start_date}} 11 query = {:created_at => {"$lte" => end_date, "$gte" => start_date}}
12 end 12 end
13 13
14 - results = benchmark("[api/v1/notices_controller] query time") { Mongoid.master["notices"].find(query, :fields => fields).to_a } 14 + results = benchmark("[api/v1/notices_controller] query time") do
  15 + Notice.where(query).with(:consistency => :strong).only(fields).to_a
  16 + end
15 17
16 respond_to do |format| 18 respond_to do |format|
17 format.html { render :json => Yajl.dump(results) } # render JSON if no extension specified on path 19 format.html { render :json => Yajl.dump(results) } # render JSON if no extension specified on path
app/controllers/api/v1/problems_controller.rb
1 class Api::V1::ProblemsController < ApplicationController 1 class Api::V1::ProblemsController < ApplicationController
2 respond_to :json, :xml 2 respond_to :json, :xml
3 - 3 +
4 def index 4 def index
5 query = {} 5 query = {}
6 fields = %w{app_id app_name environment message where first_notice_at last_notice_at resolved resolved_at notices_count} 6 fields = %w{app_id app_name environment message where first_notice_at last_notice_at resolved resolved_at notices_count}
7 - 7 +
8 if params.key?(:start_date) && params.key?(:end_date) 8 if params.key?(:start_date) && params.key?(:end_date)
9 start_date = Time.parse(params[:start_date]).utc 9 start_date = Time.parse(params[:start_date]).utc
10 end_date = Time.parse(params[:end_date]).utc 10 end_date = Time.parse(params[:end_date]).utc
11 query = {:first_notice_at=>{"$lte"=>end_date}, "$or"=>[{:resolved_at=>nil}, {:resolved_at=>{"$gte"=>start_date}}]} 11 query = {:first_notice_at=>{"$lte"=>end_date}, "$or"=>[{:resolved_at=>nil}, {:resolved_at=>{"$gte"=>start_date}}]}
12 end 12 end
13 -  
14 - results = benchmark("[api/v1/problems_controller] query time") { Mongoid.master["problems"].find(query, :fields => fields).to_a }  
15 - 13 +
  14 + results = benchmark("[api/v1/problems_controller] query time") do
  15 + Problem.where(query).with(:consistency => :strong).only(fields).to_a
  16 + end
  17 +
16 respond_to do |format| 18 respond_to do |format|
17 format.html { render :json => Yajl.dump(results) } # render JSON if no extension specified on path 19 format.html { render :json => Yajl.dump(results) } # render JSON if no extension specified on path
18 format.json { render :json => Yajl.dump(results) } 20 format.json { render :json => Yajl.dump(results) }
19 format.xml { render :xml => results } 21 format.xml { render :xml => results }
20 end 22 end
21 end 23 end
22 - 24 +
23 end 25 end
app/interactors/problem_destroy.rb
@@ -37,12 +37,12 @@ class ProblemDestroy @@ -37,12 +37,12 @@ class ProblemDestroy
37 end 37 end
38 38
39 def delete_errs 39 def delete_errs
40 - Notice.collection.remove(:err_id => { '$in' => errs_id })  
41 - Err.collection.remove(:_id => { '$in' => errs_id }) 40 + Notice.delete_all(:err_id => { '$in' => errs_id })
  41 + Err.delete_all(:_id => { '$in' => errs_id })
42 end 42 end
43 43
44 def delete_comments 44 def delete_comments
45 - Comment.collection.remove(:_id => { '$in' => comments_id }) 45 + Comment.delete_all(:_id => { '$in' => comments_id })
46 end 46 end
47 47
48 end 48 end
app/interactors/resolved_problem_clearer.rb
@@ -27,6 +27,6 @@ class ResolvedProblemClearer @@ -27,6 +27,6 @@ class ResolvedProblemClearer
27 end 27 end
28 28
29 def repair_database 29 def repair_database
30 - Mongoid.config.master.command(:repairDatabase => 1) 30 + Mongoid.default_session.command :repairDatabase => 1
31 end 31 end
32 end 32 end
app/models/app.rb
@@ -15,9 +15,6 @@ class App @@ -15,9 +15,6 @@ class App
15 field :notify_on_deploys, :type => Boolean, :default => false 15 field :notify_on_deploys, :type => Boolean, :default => false
16 field :email_at_notices, :type => Array, :default => Errbit::Config.email_at_notices 16 field :email_at_notices, :type => Array, :default => Errbit::Config.email_at_notices
17 17
18 - # Some legacy apps may have string as key instead of BSON::ObjectID  
19 - identity :type => String  
20 -  
21 embeds_many :watchers 18 embeds_many :watchers
22 embeds_many :deploys 19 embeds_many :deploys
23 embeds_one :issue_tracker 20 embeds_one :issue_tracker
@@ -61,7 +58,7 @@ class App @@ -61,7 +58,7 @@ class App
61 end 58 end
62 59
63 def self.find_by_api_key!(key) 60 def self.find_by_api_key!(key)
64 - where(:api_key => key).first || raise(Mongoid::Errors::DocumentNotFound.new(self,key)) 61 + find_by(:api_key => key)
65 end 62 end
66 63
67 def last_deploy_at 64 def last_deploy_at
app/models/backtrace.rb
@@ -3,7 +3,7 @@ class Backtrace @@ -3,7 +3,7 @@ class Backtrace
3 include Mongoid::Timestamps 3 include Mongoid::Timestamps
4 4
5 field :fingerprint 5 field :fingerprint
6 - index :fingerprint 6 + index :fingerprint => 1
7 7
8 has_many :notices 8 has_many :notices
9 has_one :notice 9 has_one :notice
@@ -19,7 +19,7 @@ class Backtrace @@ -19,7 +19,7 @@ class Backtrace
19 end 19 end
20 20
21 def similar 21 def similar
22 - Backtrace.first(:conditions => { :fingerprint => fingerprint } ) 22 + Backtrace.find_by(:fingerprint => fingerprint) rescue nil
23 end 23 end
24 24
25 def raw=(raw) 25 def raw=(raw)
app/models/comment.rb
@@ -6,7 +6,7 @@ class Comment @@ -6,7 +6,7 @@ class Comment
6 before_destroy :decrease_counter_cache 6 before_destroy :decrease_counter_cache
7 7
8 field :body, :type => String 8 field :body, :type => String
9 - index :user_id 9 + index(:user_id => 1)
10 10
11 belongs_to :err, :class_name => "Problem" 11 belongs_to :err, :class_name => "Problem"
12 belongs_to :user 12 belongs_to :user
app/models/deploy.rb
@@ -8,7 +8,7 @@ class Deploy @@ -8,7 +8,7 @@ class Deploy
8 field :revision 8 field :revision
9 field :message 9 field :message
10 10
11 - index :created_at, Mongo::DESCENDING 11 + index(:created_at => -1)
12 12
13 embedded_in :app, :inverse_of => :deploys 13 embedded_in :app, :inverse_of => :deploys
14 14
app/models/err.rb
@@ -8,8 +8,8 @@ class Err @@ -8,8 +8,8 @@ class Err
8 8
9 field :fingerprint 9 field :fingerprint
10 10
11 - index :problem_id  
12 - index :fingerprint 11 + index problem_id: 1
  12 + index fingerprint: 1
13 13
14 belongs_to :problem 14 belongs_to :problem
15 has_many :notices, :inverse_of => :err, :dependent => :destroy 15 has_many :notices, :inverse_of => :err, :dependent => :destroy
app/models/notice.rb
@@ -16,15 +16,9 @@ class Notice @@ -16,15 +16,9 @@ class Notice
16 16
17 belongs_to :err 17 belongs_to :err
18 belongs_to :backtrace, :index => true 18 belongs_to :backtrace, :index => true
19 - index :created_at  
20 -  
21 - index(  
22 - [  
23 - [ :err_id, Mongo::ASCENDING ],  
24 - [ :created_at, Mongo::ASCENDING ],  
25 - [ :_id, Mongo::ASCENDING ]  
26 - ]  
27 - ) 19 +
  20 + index(:created_at => 1)
  21 + index(:err_id => 1, :created_at => 1, :_id => 1)
28 22
29 after_create :cache_attributes_on_problem, :unresolve_problem 23 after_create :cache_attributes_on_problem, :unresolve_problem
30 after_create :email_notification 24 after_create :email_notification
app/models/problem.rb
@@ -26,14 +26,14 @@ class Problem @@ -26,14 +26,14 @@ class Problem
26 field :hosts, :type => Hash, :default => {} 26 field :hosts, :type => Hash, :default => {}
27 field :comments_count, :type => Integer, :default => 0 27 field :comments_count, :type => Integer, :default => 0
28 28
29 - index :app_id  
30 - index :app_name  
31 - index :message  
32 - index :last_notice_at  
33 - index :first_notice_at  
34 - index :last_deploy_at  
35 - index :resolved_at  
36 - index :notices_count 29 + index :app_id => 1
  30 + index :app_name => 1
  31 + index :message => 1
  32 + index :last_notice_at => 1
  33 + index :first_notice_at => 1
  34 + index :last_deploy_at => 1
  35 + index :resolved_at => 1
  36 + index :notices_count => 1
37 37
38 belongs_to :app 38 belongs_to :app
39 has_many :errs, :inverse_of => :problem, :dependent => :destroy 39 has_many :errs, :inverse_of => :problem, :dependent => :destroy
@@ -51,9 +51,9 @@ class Problem @@ -51,9 +51,9 @@ class Problem
51 validates_presence_of :last_notice_at, :first_notice_at 51 validates_presence_of :last_notice_at, :first_notice_at
52 52
53 53
54 - def self.all_else_unresolved all  
55 - if all  
56 - find(:all) 54 + def self.all_else_unresolved(fetch_all)
  55 + if fetch_all
  56 + all
57 else 57 else
58 where(:resolved => false) 58 where(:resolved => false)
59 end 59 end
@@ -132,8 +132,8 @@ class Problem @@ -132,8 +132,8 @@ class Problem
132 self.last_deploy_at = if (last_deploy = app.deploys.where(:environment => self.environment).last) 132 self.last_deploy_at = if (last_deploy = app.deploys.where(:environment => self.environment).last)
133 last_deploy.created_at.utc 133 last_deploy.created_at.utc
134 end 134 end
135 - collection.update({'_id' => self.id},  
136 - {'$set' => {'app_name' => self.app_name, 135 + collection.find('_id' => self.id)
  136 + .update({'$set' => {'app_name' => self.app_name,
137 'last_deploy_at' => self.last_deploy_at.try(:utc)}}) 137 'last_deploy_at' => self.last_deploy_at.try(:utc)}})
138 end 138 end
139 end 139 end
@@ -153,7 +153,7 @@ class Problem @@ -153,7 +153,7 @@ class Problem
153 end 153 end
154 154
155 def self.search(value) 155 def self.search(value)
156 - where.or(:error_class => /#{value}/i).or(:where => /#{value}/i).or(:message => /#{value}/i).or(:app_name => /#{value}/i).or(:environment => /#{value}/i) 156 + any_of({:error_class => /#{value}/i}, {:message => /#{value}/i}, {:app_name => /#{value}/i}, {:environment => /#{value}/i})
157 end 157 end
158 158
159 private 159 private
config/initializers/mongo.rb
@@ -20,14 +20,22 @@ elsif ENV[&#39;HEROKU&#39;] || ENV[&#39;USE_ENV&#39;] @@ -20,14 +20,22 @@ elsif ENV[&#39;HEROKU&#39;] || ENV[&#39;USE_ENV&#39;]
20 end 20 end
21 21
22 Mongoid.configure do |config| 22 Mongoid.configure do |config|
23 - config.master = Mongo::Connection.new(  
24 - settings.host,  
25 - settings.port  
26 - ).db(database_name)  
27 - config.master.authenticate(settings.user, settings.password) if settings.user 23 +
  24 + hash = {
  25 + sessions: {
  26 + default: {
  27 + database: database_name,
  28 + hosts: [ "#{settings.host}:#{settings.port}" ]
  29 + }
  30 + },
  31 + options: { allow_dynamic_fields: false, use_activesupport_time_zone: true, identity_map_enabled: true }
  32 + }
  33 +
  34 + if settings.user && settings.password
  35 + hash[:sessions][:default][:username] = settings.user
  36 + hash[:sessions][:default][:password] = settings.password
  37 + end
  38 +
  39 + config.load_configuration(hash)
28 end 40 end
29 end 41 end
30 -  
31 -Mongoid.allow_dynamic_fields = false  
32 -Mongoid.use_activesupport_time_zone = true  
33 -Mongoid.identity_map_enabled = true  
config/mongoid.example.yml
@@ -7,29 +7,34 @@ @@ -7,29 +7,34 @@
7 # `cap deploy:setup` is ran the first time. Be sure 7 # `cap deploy:setup` is ran the first time. Be sure
8 # to place production specific settings there 8 # to place production specific settings there
9 9
10 -defaults: &defaults  
11 - host: localhost  
12 - identity_map_enabled: true  
13 -  
14 - # slaves:  
15 - # - host: slave1.local  
16 - # port: 27018  
17 - # - host: slave2.local  
18 - # port: 27019  
19 -  
20 development: 10 development:
21 - <<: *defaults  
22 - database: errbit_development 11 + sessions:
  12 + default:
  13 + database: errbit_development
  14 + hosts:
  15 + - localhost:27017
  16 + options:
  17 + identity_map_enabled: true
  18 + use_utc: true
23 19
24 test: 20 test:
25 - <<: *defaults  
26 - database: errbit_test 21 + sessions:
  22 + default:
  23 + hosts:
  24 + - localhost:27017
  25 + database: errbit_test
  26 + options:
  27 + identity_map_enabled: true
  28 + use_utc: true
27 29
28 # set these environment variables on your prod server 30 # set these environment variables on your prod server
29 production: 31 production:
30 - <<: *defaults  
31 - host: <%= ENV['MONGOID_HOST'] %>  
32 - port: <%= ENV['MONGOID_PORT'] %>  
33 - username: <%= ENV['MONGOID_USERNAME'] %>  
34 - password: <%= ENV['MONGOID_PASSWORD'] %>  
35 - database: <%= ENV['MONGOID_DATABASE'] %> 32 + sessions:
  33 + default:
  34 + database: <%= ENV['MONGOID_DATABASE'] %>
  35 + hosts:
  36 + - <%=ENV["MONGOID_HOST"]%><%=ENV["MONGOID_PORT"]%>
  37 + username: <%= ENV['MONGOID_USERNAME'] %>
  38 + password: <%= ENV['MONGOID_PASSWORD'] %>
  39 + options:
  40 + identity_map_enabled: true
db/migrate/20110422152027_move_notices_to_separate_collection.rb
1 class MoveNoticesToSeparateCollection < Mongoid::Migration 1 class MoveNoticesToSeparateCollection < Mongoid::Migration
2 def self.up 2 def self.up
  3 + errs_coll = connection["errs"]
  4 +
3 # copy embedded Notices into a separate collection 5 # copy embedded Notices into a separate collection
4 - mongo_db = Err.db  
5 - errs = mongo_db.collection("errs").find({ }, :fields => ["notices"]) 6 + errs = errs_coll.find.select(notices: 1)
6 errs.each do |err| 7 errs.each do |err|
7 next unless err['notices'] 8 next unless err['notices']
8 9
@@ -18,7 +19,7 @@ class MoveNoticesToSeparateCollection &lt; Mongoid::Migration @@ -18,7 +19,7 @@ class MoveNoticesToSeparateCollection &lt; Mongoid::Migration
18 e.notices.create!(notice) 19 e.notices.create!(notice)
19 end 20 end
20 e.app.update_attribute(:notify_on_errs, old_notify) 21 e.app.update_attribute(:notify_on_errs, old_notify)
21 - mongo_db.collection("errs").update({ "_id" => err['_id']}, { "$unset" => { "notices" => 1}}) 22 + errs_coll.find({ "_id" => err['_id']}).update({ "$unset" => { "notices" => 1}})
22 end 23 end
23 Rake::Task["errbit:db:update_notices_count"].invoke 24 Rake::Task["errbit:db:update_notices_count"].invoke
24 Rake::Task["errbit:db:update_problem_attrs"].invoke 25 Rake::Task["errbit:db:update_problem_attrs"].invoke
db/migrate/20120530005915_rename_klass_to_error_class.rb
1 class RenameKlassToErrorClass < Mongoid::Migration 1 class RenameKlassToErrorClass < Mongoid::Migration
2 def self.up 2 def self.up
3 [Problem, Err, Notice].each do |model| 3 [Problem, Err, Notice].each do |model|
4 - model.collection.update({}, {'$rename' => {'klass' => 'error_class'}}, :multi => true, :safe => true) 4 + model.collection.find.update({'$rename' => {'klass' => 'error_class'}}, :multi => true, :safe => true)
5 end 5 end
6 end 6 end
7 7
8 def self.down 8 def self.down
9 [Problem, Err, Notice].each do |model| 9 [Problem, Err, Notice].each do |model|
10 - model.collection.update({}, {'$rename' => {'error_class' => 'klass'}}, :multi => true, :safe => true) 10 + model.collection.find.update({'$rename' => {'error_class' => 'klass'}}, :multi => true, :safe => true)
11 end 11 end
12 end 12 end
13 end 13 end
db/migrate/20120603112130_change_github_url_to_github_repo.rb
1 class ChangeGithubUrlToGithubRepo < Mongoid::Migration 1 class ChangeGithubUrlToGithubRepo < Mongoid::Migration
2 def self.up 2 def self.up
3 - App.collection.update({}, {'$rename' => {'github_url' => 'github_repo'}}, :multi => true, :safe => true) 3 + App.collection.find.update({'$rename' => {'github_url' => 'github_repo'}}, :multi => true, :safe => true)
4 App.all.each do |app| 4 App.all.each do |app|
5 app.send :normalize_github_repo 5 app.send :normalize_github_repo
6 app.save 6 app.save
@@ -8,7 +8,7 @@ class ChangeGithubUrlToGithubRepo &lt; Mongoid::Migration @@ -8,7 +8,7 @@ class ChangeGithubUrlToGithubRepo &lt; Mongoid::Migration
8 end 8 end
9 9
10 def self.down 10 def self.down
11 - App.collection.update({}, {'$rename' => {'github_repo' => 'github_url'}}, :multi => true, :safe => true) 11 + App.collection.find.update({'$rename' => {'github_repo' => 'github_url'}}, :multi => true, :safe => true)
12 App.all.each do |app| 12 App.all.each do |app|
13 unless app.github_repo.include?("github.com") 13 unless app.github_repo.include?("github.com")
14 app.update_attribute :github_url, "https://github.com/" << app.github_url 14 app.update_attribute :github_url, "https://github.com/" << app.github_url
@@ -12,12 +12,11 @@ puts &quot;-- email: #{admin_email}&quot; @@ -12,12 +12,11 @@ puts &quot;-- email: #{admin_email}&quot;
12 puts "-- password: #{admin_pass}" 12 puts "-- password: #{admin_pass}"
13 puts "" 13 puts ""
14 puts "Be sure to change these credentials ASAP!" 14 puts "Be sure to change these credentials ASAP!"
15 -user = User.where(:email => admin_email).first || User.new({  
16 - :name => 'Errbit Admin',  
17 - :email => admin_email,  
18 - :password => admin_pass,  
19 - :password_confirmation => admin_pass  
20 -}) 15 +user = User.find_or_initialize_by(:email => admin_email) do |u|
  16 + u.name = 'Errbit Admin'
  17 + u.password = admin_pass
  18 + u.password_confirmation = admin_pass
  19 +end
21 user.username = admin_username if Errbit::Config.user_has_username 20 user.username = admin_username if Errbit::Config.user_has_username
22 21
23 user.admin = true 22 user.admin = true
spec/controllers/api/v1/notices_controller_spec.rb
@@ -9,10 +9,10 @@ describe Api::V1::NoticesController do @@ -9,10 +9,10 @@ describe Api::V1::NoticesController do
9 9
10 describe "GET /api/v1/notices" do 10 describe "GET /api/v1/notices" do
11 before do 11 before do
12 - Fabricate(:notice, :created_at => DateTime.new(2012, 8, 01))  
13 - Fabricate(:notice, :created_at => DateTime.new(2012, 8, 01))  
14 - Fabricate(:notice, :created_at => DateTime.new(2012, 8, 21))  
15 - Fabricate(:notice, :created_at => DateTime.new(2012, 8, 30)) 12 + Fabricate(:notice, :created_at => Time.new(2012, 8, 01))
  13 + Fabricate(:notice, :created_at => Time.new(2012, 8, 01))
  14 + Fabricate(:notice, :created_at => Time.new(2012, 8, 21))
  15 + Fabricate(:notice, :created_at => Time.new(2012, 8, 30))
16 end 16 end
17 17
18 it "should return JSON if JSON is requested" do 18 it "should return JSON if JSON is requested" do
spec/controllers/apps_controller_spec.rb
@@ -11,7 +11,7 @@ describe AppsController do @@ -11,7 +11,7 @@ describe AppsController do
11 sign_in Fabricate(:admin) 11 sign_in Fabricate(:admin)
12 3.times { Fabricate(:app) } 12 3.times { Fabricate(:app) }
13 get :index 13 get :index
14 - controller.apps.should == App.all.sort.entries 14 + controller.apps.entries.should == App.all.sort.entries
15 end 15 end
16 end 16 end
17 17
spec/controllers/problems_controller_spec.rb
@@ -195,13 +195,13 @@ describe ProblemsController do @@ -195,13 +195,13 @@ describe ProblemsController do
195 sign_in Fabricate(:admin) 195 sign_in Fabricate(:admin)
196 196
197 @problem = Fabricate(:err) 197 @problem = Fabricate(:err)
198 - App.stub(:find).with(@problem.app.id).and_return(@problem.app) 198 + App.stub(:find).with(@problem.app.id.to_s).and_return(@problem.app)
199 @problem.app.problems.stub(:find).and_return(@problem.problem) 199 @problem.app.problems.stub(:find).and_return(@problem.problem)
200 @problem.problem.stub(:resolve!) 200 @problem.problem.stub(:resolve!)
201 end 201 end
202 202
203 it 'finds the app and the problem' do 203 it 'finds the app and the problem' do
204 - App.should_receive(:find).with(@problem.app.id).and_return(@problem.app) 204 + App.should_receive(:find).with(@problem.app.id.to_s).and_return(@problem.app)
205 @problem.app.problems.should_receive(:find).and_return(@problem.problem) 205 @problem.app.problems.should_receive(:find).and_return(@problem.problem)
206 put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id 206 put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id
207 controller.app.should == @problem.app 207 controller.app.should == @problem.app
spec/interactors/problem_destroy_spec.rb
@@ -32,17 +32,17 @@ describe ProblemDestroy do @@ -32,17 +32,17 @@ describe ProblemDestroy do
32 end 32 end
33 33
34 it 'delete all errs associate' do 34 it 'delete all errs associate' do
35 - Err.collection.should_receive(:remove).with(:_id => { '$in' => [err_1.id, err_2.id] }) 35 + Err.should_receive(:delete_all).with(:_id => { '$in' => [err_1.id, err_2.id] })
36 problem_destroy.execute 36 problem_destroy.execute
37 end 37 end
38 38
39 it 'delete all comments associate' do 39 it 'delete all comments associate' do
40 - Comment.collection.should_receive(:remove).with(:_id => { '$in' => [comment_1.id, comment_2.id] }) 40 + Comment.should_receive(:delete_all).with(:_id => { '$in' => [comment_1.id, comment_2.id] })
41 problem_destroy.execute 41 problem_destroy.execute
42 end 42 end
43 43
44 it 'delete all notice of associate to this errs' do 44 it 'delete all notice of associate to this errs' do
45 - Notice.collection.should_receive(:remove).with({:err_id => { '$in' => [err_1.id, err_2.id] }}) 45 + Notice.should_receive(:delete_all).with({:err_id => { '$in' => [err_1.id, err_2.id] }})
46 problem_destroy.execute 46 problem_destroy.execute
47 end 47 end
48 end 48 end
spec/interactors/problem_merge_spec.rb
@@ -38,7 +38,7 @@ describe ProblemMerge do @@ -38,7 +38,7 @@ describe ProblemMerge do
38 38
39 it 'move all err in one problem' do 39 it 'move all err in one problem' do
40 problem_merge.merge 40 problem_merge.merge
41 - problem.reload.errs.should eq (first_errs | merged_errs) 41 + expect(problem.reload.errs.map(&:id).sort).to eq (first_errs | merged_errs).map(&:id).sort
42 end 42 end
43 43
44 it 'update problem cache' do 44 it 'update problem cache' do
spec/interactors/problem_updater_cache_spec.rb
@@ -31,11 +31,11 @@ describe ProblemUpdaterCache do @@ -31,11 +31,11 @@ describe ProblemUpdaterCache do
31 end 31 end
32 32
33 it 'update first_notice_at' do 33 it 'update first_notice_at' do
34 - expect(problem.first_notice_at).to eq notice.created_at 34 + expect(problem.first_notice_at).to eq notice.reload.created_at
35 end 35 end
36 36
37 it 'update last_notice_at' do 37 it 'update last_notice_at' do
38 - expect(problem.last_notice_at).to eq notice.created_at 38 + expect(problem.last_notice_at).to eq notice.reload.created_at
39 end 39 end
40 40
41 it 'update stats messages' do 41 it 'update stats messages' do
spec/interactors/resolved_problem_clearer_spec.rb
@@ -21,16 +21,16 @@ describe ResolvedProblemClearer do @@ -21,16 +21,16 @@ describe ResolvedProblemClearer do
21 } 21 }
22 end 22 end
23 it 'not repair database' do 23 it 'not repair database' do
24 - Mongoid.config.master.should_receive(:command).and_call_original  
25 - Mongoid.config.master.should_not_receive(:command).with({:repairDatabase => 1}) 24 + Mongoid.default_session.stub(:command).and_call_original
  25 + Mongoid.default_session.should_not_receive(:command).with({:repairDatabase => 1})
26 resolved_problem_clearer.execute 26 resolved_problem_clearer.execute
27 end 27 end
28 end 28 end
29 29
30 context "with problem resolve" do 30 context "with problem resolve" do
31 before do 31 before do
32 - Mongoid.config.master.stub(:command).and_call_original  
33 - Mongoid.config.master.stub(:command).with({:repairDatabase => 1}) 32 + Mongoid.default_session.stub(:command).and_call_original
  33 + Mongoid.default_session.stub(:command).with({:repairDatabase => 1})
34 problems.first.resolve! 34 problems.first.resolve!
35 problems.second.resolve! 35 problems.second.resolve!
36 end 36 end
@@ -46,8 +46,8 @@ describe ResolvedProblemClearer do @@ -46,8 +46,8 @@ describe ResolvedProblemClearer do
46 end 46 end
47 47
48 it 'repair database' do 48 it 'repair database' do
49 - Mongoid.config.master.should_receive(:command).and_call_original  
50 - Mongoid.config.master.should_receive(:command).with({:repairDatabase => 1}) 49 + Mongoid.default_session.stub(:command).and_call_original
  50 + Mongoid.default_session.should_receive(:command).with({:repairDatabase => 1})
51 resolved_problem_clearer.execute 51 resolved_problem_clearer.execute
52 end 52 end
53 end 53 end