Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix Image spec tests

  • Loading branch information...
commit a42e42cc172891506b3a2cf3c8a5cc81b579bd88 1 parent 3249212
@psndcsrv psndcsrv authored
Showing with 27 additions and 18 deletions.
  1. +14 −18 spec/controllers/images_controller_spec.rb
  2. +13 −0 spec/models/image_spec.rb
View
32 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
View
13 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
Please sign in to comment.
Something went wrong with that request. Please try again.