Skip to content

Commit

Permalink
Fix Image spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psndcsrv committed Jun 4, 2012
1 parent 3249212 commit a42e42c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
32 changes: 14 additions & 18 deletions 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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
13 changes: 13 additions & 0 deletions 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

0 comments on commit a42e42c

Please sign in to comment.