From ab993f9e5e10f47637676ef38738ebb964f7a5ad Mon Sep 17 00:00:00 2001 From: Sam Joseph Date: Thu, 1 Aug 2013 18:03:51 +0900 Subject: [PATCH] getting rid of the deprecation warnings from the upgrade to rails 3.2? --- app/models/category_organization.rb | 2 +- .../organizations_controller_spec.rb | 154 +++++++++--------- spec/models/organization_spec.rb | 2 +- .../organizations/index.html.erb_spec.rb | 6 +- 4 files changed, 82 insertions(+), 82 deletions(-) diff --git a/app/models/category_organization.rb b/app/models/category_organization.rb index c4f1de689..f0c2a28e7 100644 --- a/app/models/category_organization.rb +++ b/app/models/category_organization.rb @@ -1,3 +1,3 @@ class CategoryOrganization < ActiveRecord::Base - set_table_name 'categories_organizations' + self.table_name = 'categories_organizations' end \ No newline at end of file diff --git a/spec/controllers/organizations_controller_spec.rb b/spec/controllers/organizations_controller_spec.rb index 06679dd1e..45922d395 100644 --- a/spec/controllers/organizations_controller_spec.rb +++ b/spec/controllers/organizations_controller_spec.rb @@ -7,19 +7,19 @@ FactoryGirl.find_definitions end - def mock_organization(stubs={}) - (@mock_organization ||= mock_model(Organization).as_null_object).tap do |organization| + def double_organization(stubs={}) + (@double_organization ||= mock_model(Organization).as_null_object).tap do |organization| organization.stub(stubs) unless stubs.empty? end end describe "popup partial" do it "should take some argument and call to_gmap4rails on it" do - result = [mock_organization] - partial = mock("template") - marker = mock("marker") + result = [double_organization] + partial = double("template") + marker = double("marker") marker.should_receive(:infowindow) - result.should_receive(:to_gmaps4rails).and_yield(mock_organization,marker) + result.should_receive(:to_gmaps4rails).and_yield(double_organization,marker) @controller.should_receive(:render_to_string) #not sure if we are supposed to test private method on controller ... @controller.send(:gmap4rails_with_popup_partial,result, partial) @@ -32,7 +32,7 @@ def mock_organization(stubs={}) context 'setting appropriate view vars for all combinations of input' do let(:json) {'my markers'} let(:result) do - [mock_organization] + [double_organization] end before(:each) do result.should_receive(:to_gmaps4rails).and_return(json) @@ -40,7 +40,7 @@ def mock_organization(stubs={}) end it "sets up appropriate values for view vars: query_term, organizations and json" do - category = mock('Category') + category = double('Category') Organization.should_receive(:search_by_keyword).with('test').and_return(result) result.should_receive(:filter_by_category).with('1').and_return(result) Category.should_receive(:find_by_id).with("1").and_return(category) @@ -80,35 +80,35 @@ def mock_organization(stubs={}) after(:each) do response.should render_template 'index' - assigns(:organizations).should eq([mock_organization]) + assigns(:organizations).should eq([double_organization]) assigns(:json).should eq(json) end end # TODO figure out how to make this less messy it "assigns to flash.now but not flash when search returns no results" do - mock_now_flash = double("FlashHash") + double_now_flash = double("FlashHash") result = [] result.should_receive(:empty?).and_return(true) result.stub_chain(:page, :per).and_return(result) Organization.should_receive(:search_by_keyword).with('no results').and_return(result) result.should_receive(:filter_by_category).with('1').and_return(result) - category = mock('Category') + category = double('Category') Category.should_receive(:find_by_id).with("1").and_return(category) - ActionDispatch::Flash::FlashHash.any_instance.should_receive(:now).and_return mock_now_flash + ActionDispatch::Flash::FlashHash.any_instance.should_receive(:now).and_return double_now_flash ActionDispatch::Flash::FlashHash.any_instance.should_not_receive(:[]=) - mock_now_flash.should_receive(:[]=).with(:alert, "Sorry, it seems we don't quite have what you are looking for.") + double_now_flash.should_receive(:[]=).with(:alert, "Sorry, it seems we don't quite have what you are looking for.") get :search , :q => 'no results' , "category" => {"id"=>"1"} end it "does not set up flash nor flash.now when search returns results" do - result = [mock_organization] + result = [double_organization] json='my markers' result.should_receive(:to_gmaps4rails).and_return(json) result.should_receive(:empty?).and_return(false) result.stub_chain(:page, :per).and_return(result) Organization.should_receive(:search_by_keyword).with('some results').and_return(result) result.should_receive(:filter_by_category).with('1').and_return(result) - category = mock('Category') + category = double('Category') Category.should_receive(:find_by_id).with("1").and_return(category) get :search , :q => 'some results' , "category" => {"id"=>"1"} expect(flash.now[:alert]).to be_nil @@ -119,7 +119,7 @@ def mock_organization(stubs={}) describe "GET index" do it "assigns all organizations as @organizations" do - result = [mock_organization] + result = [double_organization] json='my markers' result.should_receive(:to_gmaps4rails).and_return(json) Organization.should_receive(:order).with('updated_at DESC').and_return(result) @@ -133,35 +133,35 @@ def mock_organization(stubs={}) describe "GET show" do it "assigns the requested organization as @organization and appropriate json" do json='my markers' - @org = mock_organization + @org = double_organization @org.should_receive(:to_gmaps4rails).and_return(json) Organization.should_receive(:find).with("37") { @org } get :show, :id => "37" - assigns(:organization).should be(mock_organization) + assigns(:organization).should be(double_organization) assigns(:json).should eq(json) end context "editable flag is assigned to match user permission" do before(:each) do - Organization.stub(:find).with("37") { mock_organization } - @user = mock_model("User") - controller.stub!(:current_user).and_return(@user) + Organization.stub(:find).with("37") { double_organization } + @user = double("User") + controller.stub(:current_user).and_return(@user) end it "user with permission leads to editable flag true" do - @user.should_receive(:can_edit?).with(mock_organization).and_return(true) + @user.should_receive(:can_edit?).with(double_organization).and_return(true) get :show, :id => 37 assigns(:editable).should be(true) end it "user without permission leads to editable flag false" do - @user.should_receive(:can_edit?).with(mock_organization).and_return(true) + @user.should_receive(:can_edit?).with(double_organization).and_return(true) get :show, :id => 37 assigns(:editable).should be(true) end it 'when not signed in editable flag is nil' do - controller.stub!(:current_user).and_return(nil) + controller.stub(:current_user).and_return(nil) get :show, :id => 37 expect(assigns(:editable)).to eq nil end @@ -171,15 +171,15 @@ def mock_organization(stubs={}) describe "GET new" do context "while signed in" do before(:each) do - user = mock_model("User") + user = double("User") request.env['warden'].stub :authenticate! => user - controller.stub!(:current_user).and_return(user) + controller.stub(:current_user).and_return(user) end it "assigns a new organization as @organization" do - Organization.stub(:new) { mock_organization } + Organization.stub(:new) { double_organization } get :new - assigns(:organization).should be(mock_organization) + assigns(:organization).should be(double_organization) end end @@ -194,15 +194,15 @@ def mock_organization(stubs={}) describe "GET edit" do context "while signed in" do before(:each) do - user = mock_model("User") + user = double("User") request.env['warden'].stub :authenticate! => user - controller.stub!(:current_user).and_return(user) + controller.stub(:current_user).and_return(user) end it "assigns the requested organization as @organization" do - Organization.stub(:find).with("37") { mock_organization } + Organization.stub(:find).with("37") { double_organization } get :edit, :id => "37" - assigns(:organization).should be(mock_organization) + assigns(:organization).should be(double_organization) end end #TODO: way to dry out these redirect specs? @@ -217,35 +217,35 @@ def mock_organization(stubs={}) describe "POST create" do context "while signed in as admin" do before(:each) do - user = mock_model("User") + user = double("User") request.env['warden'].stub :authenticate! => user - controller.stub!(:current_user).and_return(user) + controller.stub(:current_user).and_return(user) user.should_receive(:admin?).and_return(true) end describe "with valid params" do it "assigns a newly created organization as @organization" do - Organization.stub(:new).with({'these' => 'params'}) { mock_organization(:save => true) } + Organization.stub(:new).with({'these' => 'params'}) { double_organization(:save => true, :name => 'org') } post :create, :organization => {'these' => 'params'} - assigns(:organization).should be(mock_organization) + assigns(:organization).should be(double_organization) end it "redirects to the created organization" do - Organization.stub(:new) { mock_organization(:save => true) } + Organization.stub(:new) { double_organization(:save => true) } post :create, :organization => {} - response.should redirect_to(organization_url(mock_organization)) + response.should redirect_to(organization_url(double_organization)) end end describe "with invalid params" do it "assigns a newly created but unsaved organization as @organization" do - Organization.stub(:new).with({'these' => 'params'}) { mock_organization(:save => false) } + Organization.stub(:new).with({'these' => 'params'}) { double_organization(:save => false) } post :create, :organization => {'these' => 'params'} - assigns(:organization).should be(mock_organization) + assigns(:organization).should be(double_organization) end it "re-renders the 'new' template" do - Organization.stub(:new) { mock_organization(:save => false) } + Organization.stub(:new) { double_organization(:save => false) } post :create, :organization => {} response.should render_template("new") end @@ -254,7 +254,7 @@ def mock_organization(stubs={}) context "while not signed in" do it "redirects to sign-in" do - Organization.stub(:new).with({'these' => 'params'}) { mock_organization(:save => true) } + Organization.stub(:new).with({'these' => 'params'}) { double_organization(:save => true) } post :create, :organization => {'these' => 'params'} expect(response).to redirect_to new_user_session_path end @@ -262,26 +262,26 @@ def mock_organization(stubs={}) context "while signed in as non-admin" do before(:each) do - user = mock_model("User") + user = double("User") request.env['warden'].stub :authenticate! => user - controller.stub!(:current_user).and_return(user) + controller.stub(:current_user).and_return(user) user.should_receive(:admin?).and_return(false) end describe "with valid params" do it "refuses to create a new organization" do # stubbing out Organization to prevent new method from calling Gmaps APIs - Organization.stub(:new).with({'these' => 'params'}) { mock_organization(:save => true) } + Organization.stub(:new).with({'these' => 'params'}) { double_organization(:save => true) } Organization.should_not_receive :new post :create, :organization => {'these' => 'params'} end it "redirects to the organizations index" do - Organization.stub(:new).with({'these' => 'params'}) { mock_organization(:save => true) } + Organization.stub(:new).with({'these' => 'params'}) { double_organization(:save => true) } post :create, :organization => {'these' => 'params'} expect(response).to redirect_to organizations_path end it "assigns a flash refusal" do - Organization.stub(:new).with({'these' => 'params'}) { mock_organization(:save => true) } + Organization.stub(:new).with({'these' => 'params'}) { double_organization(:save => true) } post :create, :organization => {'these' => 'params'} expect(flash[:notice]).to eq("You don't have permission") end @@ -293,43 +293,43 @@ def mock_organization(stubs={}) describe "PUT update" do context "while signed in as user who can edit" do before(:each) do - user = mock_model("User") - user.stub!(:can_edit?){true} + user = double("User") + user.stub(:can_edit?){true} request.env['warden'].stub :authenticate! => user - controller.stub!(:current_user).and_return(user) + controller.stub(:current_user).and_return(user) end describe "with valid params" do it "updates org for e.g. donation_info url" do - mock = mock_organization(:id => 37) - Organization.should_receive(:find).with("37"){mock} - mock_organization.should_receive(:update_attributes).with({'donation_info' => 'http://www.friendly.com/donate'}) + double = double_organization(:id => 37, :model_name => 'Organization') + Organization.should_receive(:find).with("37"){double} + double_organization.should_receive(:update_attributes).with({'donation_info' => 'http://www.friendly.com/donate'}) put :update, :id => "37", :organization => {'donation_info' => 'http://www.friendly.com/donate'} end it "assigns the requested organization as @organization" do - Organization.stub(:find) { mock_organization(:update_attributes => true) } + Organization.stub(:find) { double_organization(:update_attributes => true) } put :update, :id => "1" - assigns(:organization).should be(mock_organization) + assigns(:organization).should be(double_organization) end it "redirects to the organization" do - Organization.stub(:find) { mock_organization(:update_attributes => true) } + Organization.stub(:find) { double_organization(:update_attributes => true) } put :update, :id => "1" - response.should redirect_to(organization_url(mock_organization)) + response.should redirect_to(organization_url(double_organization)) end end describe "with invalid params" do it "assigns the organization as @organization" do - Organization.stub(:find) { mock_organization(:update_attributes => false) } + Organization.stub(:find) { double_organization(:update_attributes => false) } put :update, :id => "1" - assigns(:organization).should be(mock_organization) + assigns(:organization).should be(double_organization) end it "re-renders the 'edit' template" do - Organization.stub(:find) { mock_organization(:update_attributes => false) } + Organization.stub(:find) { double_organization(:update_attributes => false) } put :update, :id => "1" response.should render_template("edit") end @@ -338,15 +338,15 @@ def mock_organization(stubs={}) context "while signed in as user who cannot edit" do before(:each) do - user = mock_model("User") - user.stub!(:can_edit?){false} + user = double("User") + user.stub(:can_edit?){false} request.env['warden'].stub :authenticate! => user - controller.stub!(:current_user).and_return(user) + controller.stub(:current_user).and_return(user) end describe "with existing organization" do it "does not update the requested organization" do - org = mock_organization(:id => 37) + org = double_organization(:id => 37) Organization.should_receive(:find).with("#{org.id}") {org} org.should_not_receive(:update_attributes) put :update, :id => "#{org.id}", :organization => {'these' => 'params'} @@ -376,39 +376,39 @@ def mock_organization(stubs={}) describe "DELETE destroy" do context "while signed in as admin" do before(:each) do - user = mock_model("User") - user.stub!(:admin?){true} + user = double("User") + user.stub(:admin?){true} request.env['warden'].stub :authenticate! => user - controller.stub!(:current_user).and_return(user) + controller.stub(:current_user).and_return(user) end it "destroys the requested organization" do - Organization.should_receive(:find).with("37") { mock_organization } - mock_organization.should_receive(:destroy) + Organization.should_receive(:find).with("37") { double_organization } + double_organization.should_receive(:destroy) delete :destroy, :id => "37" end it "redirects to the organizations list" do - Organization.stub(:find) { mock_organization } + Organization.stub(:find) { double_organization } delete :destroy, :id => "1" response.should redirect_to(organizations_url) end end context "while signed in as non-admin" do before(:each) do - user = mock_model("User") - user.stub!(:admin?){false} + user = double("User") + user.stub(:admin?){false} request.env['warden'].stub :authenticate! => user - controller.stub!(:current_user).and_return(user) + controller.stub(:current_user).and_return(user) end it "does not destroy the requested organization" do - mock = mock_organization - Organization.should_not_receive(:find).with("37"){mock} - mock.should_not_receive(:destroy) + double = double_organization + Organization.should_not_receive(:find).with("37"){double} + double.should_not_receive(:destroy) delete :destroy, :id => "37" end it "redirects to the organization home page" do - Organization.stub(:find) { mock_organization } + Organization.stub(:find) { double_organization } delete :destroy, :id => "1" response.should redirect_to(organization_url(1)) end diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index da0c0e7b7..536780f26 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -258,7 +258,7 @@ def create_organization(fields) it "should import categories when matching org is found" do Organization.should_receive(:check_columns_in).with(row) Organization.should_receive(:find_by_name).with('Harrow Bereavement Counselling').and_return @org1 - array = mock('Array') + array = double('Array') [{:cc_id => 207, :cat => @cat1}, {:cc_id => 305, :cat => @cat2}, {:cc_id => 108, :cat => @cat3}, {:cc_id => 302, :cat => @cat4}, {:cc_id => 306, :cat => @cat5}]. each do |cat_hash| Category.should_receive(:find_by_charity_commission_id).with(cat_hash[:cc_id]).and_return(cat_hash[:cat]) diff --git a/spec/views/organizations/index.html.erb_spec.rb b/spec/views/organizations/index.html.erb_spec.rb index 3a0947efc..df684722b 100644 --- a/spec/views/organizations/index.html.erb_spec.rb +++ b/spec/views/organizations/index.html.erb_spec.rb @@ -22,9 +22,9 @@ assign(:organizations, organizations) assign(:results, results) assign(:query_term,'search') - organizations.stub!(:current_page).and_return(1) - organizations.stub!(:total_pages).and_return(1) - organizations.stub!(:limit_value).and_return(1) + organizations.stub(:current_page).and_return(1) + organizations.stub(:total_pages).and_return(1) + organizations.stub(:limit_value).and_return(1) assign(:category_options, [['Animal Welfare','1'],['Education','2']]) render end