From a42e42cc172891506b3a2cf3c8a5cc81b579bd88 Mon Sep 17 00:00:00 2001 From: Aaron Unger Date: Mon, 4 Jun 2012 11:01:30 -0700 Subject: [PATCH] Fix Image spec tests --- spec/controllers/images_controller_spec.rb | 32 ++++++++++------------ spec/models/image_spec.rb | 13 +++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/spec/controllers/images_controller_spec.rb b/spec/controllers/images_controller_spec.rb index cdab91c8d4..0ee526cc2e 100644 --- a/spec/controllers/images_controller_spec.rb +++ b/spec/controllers/images_controller_spec.rb @@ -1,10 +1,18 @@ require File.expand_path('../../spec_helper', __FILE__) +SAMPLE_IMAGE = "#{RAILS_ROOT}/public/images/cc-footer.png" unless defined?(SAMPLE_IMAGE) + describe ImagesController do + def mock_image_image(stubs={}) + stubs = {:path => SAMPLE_IMAGE}.merge(stubs) + @mock_image_image ||= mock_model(Object, stubs) + end + def mock_image(stubs={}) + stubs = {:name => "Image", :attribution => "Image subtext", :image => mock_image_image, :changeable? => true, :reload => true, :user= => true}.merge(stubs) @mock_image ||= mock_model(Image, stubs) end - + before(:each) do login_admin end @@ -13,23 +21,11 @@ def mock_image(stubs={}) describe "responding to GET index" do it "should expose an array of all the @images" do - Image.should_receive(:find).with(:all).and_return([mock_image]) + Image.should_receive(:find).with(:all, {:limit=>36, :offset=>0}).and_return([mock_image]) get :index assigns[:images].should == [mock_image] end - describe "with mime type of xml" do - - it "should render all images as xml" do - request.env["HTTP_ACCEPT"] = "application/xml" - Image.should_receive(:find).with(:all).and_return(images = mock("Array of Images")) - images.should_receive(:to_xml).and_return("generated XML") - get :index - response.body.should == "generated XML" - end - - end - end describe "responding to GET show" do @@ -122,13 +118,13 @@ def mock_image(stubs={}) it "should expose the requested image as @image" do Image.stub!(:find).and_return(mock_image(:update_attributes => true)) - put :update, :id => "1" + put :update, :id => "1", :image => {:these => 'params'} assigns(:image).should equal(mock_image) end it "should redirect to the image" do Image.stub!(:find).and_return(mock_image(:update_attributes => true)) - put :update, :id => "1" + put :update, :id => "1", :image => {:these => 'params'} response.should redirect_to(image_url(mock_image)) end @@ -144,13 +140,13 @@ def mock_image(stubs={}) it "should expose the image as @image" do Image.stub!(:find).and_return(mock_image(:update_attributes => false)) - put :update, :id => "1" + put :update, :id => "1", :image => {:these => 'params'} assigns(:image).should equal(mock_image) end it "should re-render the 'edit' template" do Image.stub!(:find).and_return(mock_image(:update_attributes => false)) - put :update, :id => "1" + put :update, :id => "1", :image => {:these => 'params'} response.should render_template('edit') end diff --git a/spec/models/image_spec.rb b/spec/models/image_spec.rb index 1f7ca86204..e97680a32a 100644 --- a/spec/models/image_spec.rb +++ b/spec/models/image_spec.rb @@ -1,12 +1,25 @@ require File.expand_path('../../spec_helper', __FILE__) +SAMPLE_IMAGE = "#{RAILS_ROOT}/public/images/cc-footer.png" unless defined?(SAMPLE_IMAGE) describe Image do before(:each) do + user = Factory(:user) @valid_attributes = { + :name => "Image Test", + :attribution => "Some subtitle", + :image => File.open(SAMPLE_IMAGE), + :user => user } end it "should create a new instance given valid attributes" do Image.create!(@valid_attributes) end + + it "should create static images in the filesystem" do + i = Image.create!(@valid_attributes) + %w{original attributed thumb}.each do |type| + File.exists?("#{RAILS_ROOT}/public/system/images/#{i.id}/#{type}/cc-footer.png").should be_true + end + end end