Commit d6061dfff5b438d9581d08bfcad2517bcf61770b
1 parent
95c2aa13
Exists in
master
and in
1 other branch
Fix strange bugs with scoping mongoid objects over different types of relations
Showing
6 changed files
with
15 additions
and
10 deletions
Show diff stats
app/controllers/errs_controller.rb
| ... | ... | @@ -21,7 +21,7 @@ class ErrsController < ApplicationController |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | def resolve |
| 24 | - @err = @app.errs.unresolved.find(params[:id]) | |
| 24 | + @err = @app.errs.find(params[:id]) | |
| 25 | 25 | |
| 26 | 26 | # Deal with bug in mogoid where find is returning an Enumberable obj |
| 27 | 27 | @err = @err.first if @err.respond_to?(:first) | ... | ... |
app/models/app.rb
| ... | ... | @@ -22,8 +22,7 @@ class App |
| 22 | 22 | |
| 23 | 23 | # Mongoid Bug: find(id) on association proxies returns an Enumerator |
| 24 | 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 | 26 | end |
| 28 | 27 | |
| 29 | 28 | def self.find_by_api_key!(key) | ... | ... |
app/models/user.rb
| ... | ... | @@ -16,11 +16,14 @@ class User |
| 16 | 16 | # Mongoid doesn't seem to currently support |
| 17 | 17 | # referencing embedded documents |
| 18 | 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 | 20 | end |
| 21 | 21 | |
| 22 | 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 | 27 | end |
| 25 | 28 | |
| 26 | 29 | def watching?(app) | ... | ... |
app/views/errs/_table.html.haml
public/stylesheets/application.css
| ... | ... | @@ -476,6 +476,11 @@ table.errs td.message em { |
| 476 | 476 | color: #727272; |
| 477 | 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 | 485 | /* Notices Pagination */ |
| 481 | 486 | .notice-pagination { | ... | ... |
spec/controllers/errs_controller_spec.rb
| ... | ... | @@ -123,15 +123,13 @@ describe ErrsController do |
| 123 | 123 | |
| 124 | 124 | @err = Factory(:err) |
| 125 | 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 | 127 | @err.stub(:resolve!) |
| 129 | 128 | end |
| 130 | 129 | |
| 131 | 130 | it 'finds the app and the err' do |
| 132 | 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 | 133 | put :resolve, :app_id => @err.app.id, :id => @err.id |
| 136 | 134 | assigns(:app).should == @err.app |
| 137 | 135 | assigns(:err).should == @err | ... | ... |