Commit d6061dfff5b438d9581d08bfcad2517bcf61770b

Authored by Jared Pace
1 parent 95c2aa13
Exists in master and in 1 other branch production

Fix strange bugs with scoping mongoid objects over different types of relations

app/controllers/errs_controller.rb
@@ -21,7 +21,7 @@ class ErrsController < ApplicationController @@ -21,7 +21,7 @@ class ErrsController < ApplicationController
21 end 21 end
22 22
23 def resolve 23 def resolve
24 - @err = @app.errs.unresolved.find(params[:id]) 24 + @err = @app.errs.find(params[:id])
25 25
26 # Deal with bug in mogoid where find is returning an Enumberable obj 26 # Deal with bug in mogoid where find is returning an Enumberable obj
27 @err = @err.first if @err.respond_to?(:first) 27 @err = @err.first if @err.respond_to?(:first)
app/models/app.rb
@@ -22,8 +22,7 @@ class App @@ -22,8 +22,7 @@ class App
22 22
23 # Mongoid Bug: find(id) on association proxies returns an Enumerator 23 # Mongoid Bug: find(id) on association proxies returns an Enumerator
24 def self.find_by_id!(app_id) 24 def self.find_by_id!(app_id)
25 - raise app_id.inspect  
26 - where(:id => app_id).first || raise(Mongoid::Errors::DocumentNotFound.new(self,app_id)) 25 + where(:_id => app_id).first || raise(Mongoid::Errors::DocumentNotFound.new(self,app_id))
27 end 26 end
28 27
29 def self.find_by_api_key!(key) 28 def self.find_by_api_key!(key)
app/models/user.rb
@@ -16,11 +16,14 @@ class User @@ -16,11 +16,14 @@ class User
16 # Mongoid doesn't seem to currently support 16 # Mongoid doesn't seem to currently support
17 # referencing embedded documents 17 # referencing embedded documents
18 def watchers 18 def watchers
19 - App.all.map(&:watchers).flatten.select {|w| w.user_id == id} 19 + App.all.map(&:watchers).flatten.select {|w| w.user_id.to_s == id.to_s}
20 end 20 end
21 21
22 def apps 22 def apps
23 - App.where('watchers.user_id' => id.to_s) 23 + # This is completely wasteful but became necessary
  24 + # due to bugs in Mongoid
  25 + app_ids = watchers.map {|w| w.app.id}
  26 + App.any_in(:_id => app_ids)
24 end 27 end
25 28
26 def watching?(app) 29 def watching?(app)
app/views/errs/_table.html.haml
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 %th Count 8 %th Count
9 %tbody 9 %tbody
10 - errs.each do |err| 10 - errs.each do |err|
11 - %tr 11 + %tr{:class => err.resolved? ? 'resolved' : 'unresolved'}
12 %td.app 12 %td.app
13 = err.app.name 13 = err.app.name
14 %span.environment= err.environment 14 %span.environment= err.environment
public/stylesheets/application.css
@@ -476,6 +476,11 @@ table.errs td.message em { @@ -476,6 +476,11 @@ table.errs td.message em {
476 color: #727272; 476 color: #727272;
477 font-size: 0.9em; 477 font-size: 0.9em;
478 } 478 }
  479 +table.errs tr.resolved td > * {
  480 + opacity: 0.5;
  481 + -moz-opacity: 0.5;
  482 + -webkit-opacity: 0.5;
  483 +}
479 484
480 /* Notices Pagination */ 485 /* Notices Pagination */
481 .notice-pagination { 486 .notice-pagination {
spec/controllers/errs_controller_spec.rb
@@ -123,15 +123,13 @@ describe ErrsController do @@ -123,15 +123,13 @@ describe ErrsController do
123 123
124 @err = Factory(:err) 124 @err = Factory(:err)
125 App.stub(:find).with(@err.app.id).and_return(@err.app) 125 App.stub(:find).with(@err.app.id).and_return(@err.app)
126 - @err.app.errs.stub(:unresolved).  
127 - and_return(stub('proxy', :find => @err)) 126 + @err.app.errs.stub(:find).and_return(@err)
128 @err.stub(:resolve!) 127 @err.stub(:resolve!)
129 end 128 end
130 129
131 it 'finds the app and the err' do 130 it 'finds the app and the err' do
132 App.should_receive(:find).with(@err.app.id).and_return(@err.app) 131 App.should_receive(:find).with(@err.app.id).and_return(@err.app)
133 - @err.app.errs.should_receive(:unresolved).  
134 - and_return(mock('proxy', :find => @err)) 132 + @err.app.errs.should_receive(:find).and_return(@err)
135 put :resolve, :app_id => @err.app.id, :id => @err.id 133 put :resolve, :app_id => @err.app.id, :id => @err.id
136 assigns(:app).should == @err.app 134 assigns(:app).should == @err.app
137 assigns(:err).should == @err 135 assigns(:err).should == @err