Skip to content
Browse files

improvement (DRY) of the tests on logo uploads

  • Loading branch information...
1 parent 54ae80a commit 54ebf889d179fb7e37421e12e190c6dbf8a5cb4d mose committed Nov 13, 2011
Showing with 44 additions and 48 deletions.
  1. +44 −48 spec/controllers/settings_controller_spec.rb
View
92 spec/controllers/settings_controller_spec.rb
@@ -22,62 +22,58 @@
end
end
- describe :change_logo do
-
- it "uploads a remote logo" do
- image_path = Rails.root.to_s + "/public/themes/fracture/images/logo.png" # location of main logo
- if File.file?(image_path)
- image_saved = Rails.root.to_s + "/public/themes/fracture/images/logo-saved.png" # temp save location for the original logo
- FileUtils.mv(image_path, image_saved)
+ describe "handling the site logo" do
+ before(:all) do
+ @image_path = Rails.root.to_s + "/public/themes/fracture/images/logo.png" # location of main logo
+ if File.file?(@image_path)
+ @image_saved = Rails.root.to_s + "/public/themes/fracture/images/logo-saved.png" # temp save location for the original logo
+ FileUtils.mv(@image_path, @image_saved)
end
- post(:change_logo, { :source => :remote, :url => "http://hulihanapplications.com/images/quick_links/opal_tiny.png" } )
- flash[:success].should_not == nil
- File.file?(image_path).should == true
- response.should redirect_to(:action => :index, :controller => :settings)
- FileUtils.rm(image_path)
- FileUtils.mv(image_saved, image_path) unless image_saved.nil?
+
+ end
+
+ after(:all) do
+ FileUtils.rm(@image_path) if File.file?(@image_path)
+ FileUtils.mv(@image_saved, @image_path) unless @image_saved.nil?
end
+
+ describe :change_logo do
- it "uploads a local logo" do
- image_path = Rails.root.to_s + "/public/themes/fracture/images/logo.png" # location of main logo
- @testimage = fixture_file_upload(Rails.root.to_s + '/spec/fixtures/images/example.png')
- # start of dirty-hack-that-we-should-get-rid-off-soon
- # this hack was suggested on http://stackoverflow.com/questions/7793510/mocking-file-uploads-in-rails-3-1-controller-tests
- # and is mostly for rails 3 compat. Smells a bit bad but well, it works ...
- class << @testimage
- attr_reader :tempfile
+ it "uploads a remote logo" do
+ post(:change_logo, { :source => :remote, :url => "http://hulihanapplications.com/images/quick_links/opal_tiny.png" } )
+ flash[:success].should_not == nil
+ File.file?(@image_path).should == true
+ response.should redirect_to(:action => :index, :controller => :settings)
end
- # end of dirty-hack-that-we-should-get-rid-off-soon
- if File.file?(image_path)
- image_saved = Rails.root.to_s + "/public/themes/fracture/images/logo-saved.png" # temp save location for the original logo
- FileUtils.mv(image_path, image_saved)
+
+ it "uploads a local logo" do
+ @testimage = fixture_file_upload(Rails.root.to_s + '/spec/fixtures/images/example.png')
+ # start of dirty-hack-that-we-should-get-rid-off-soon
+ # this hack was suggested on http://stackoverflow.com/questions/7793510/mocking-file-uploads-in-rails-3-1-controller-tests
+ # and is mostly for rails 3 compat. Smells a bit bad but well, it works ...
+ class << @testimage
+ attr_reader :tempfile
+ end
+ # end of dirty-hack-that-we-should-get-rid-off-soon
+ post(:change_logo, { :source => :local, :file => @testimage })
+ flash[:success].should_not == nil
+ File.file?(@image_path).should == true
+ response.should redirect_to(:action => :index, :controller => :settings)
end
- post(:change_logo, { :source => :local, :file => @testimage })
- flash[:success].should_not == nil
- File.file?(image_path).should == true
- response.should redirect_to(:action => :index, :controller => :settings)
- FileUtils.rm(image_path)
- FileUtils.mv(image_saved, image_path) unless image_saved.nil?
+ pending "uploading a non-image logo"
end
- pending "uploading a non-image logo"
- end
- describe :delete_logo do
- it "really erases the logo" do
- image_path = Rails.root.to_s + "/public/themes/fracture/images/logo.png" # location of main logo
- if File.file?(image_path)
- image_saved = Rails.root.to_s + "/public/themes/fracture/images/logo-saved.png" # temp save location for the original logo
- FileUtils.mv(image_path, image_saved)
+ describe :delete_logo do
+ it "really erases the logo" do
+ FileUtils.touch(@image_path)
+ get(:delete_logo)
+ flash[:success].should_not == nil
+ File.file?(@image_path).should == false
+ response.should redirect_to(:action => :index, :controller => :settings, :anchor => :Logo)
end
- FileUtils.touch(image_path)
- get(:delete_logo)
- flash[:success].should_not == nil
- File.file?(image_path).should == false
- response.should redirect_to(:action => :index, :controller => :settings, :anchor => :Logo)
- FileUtils.mv(image_saved, image_path) unless image_saved.nil?
- end
- end
-
+ end
+ end
+
describe :themes do
it "returns 200" do
get :themes

0 comments on commit 54ebf88

Please sign in to comment.
Something went wrong with that request. Please try again.