Permalink
Browse files

Added basic test infrastructure

  • Loading branch information...
1 parent 0dd587e commit 6ba647b3b44a22b1f8c76939dc75eaf5a4bf9265 @cvortmann committed Mar 30, 2012
Showing with 60 additions and 4 deletions.
  1. +2 −0 Gemfile
  2. +5 −0 Gemfile.lock
  3. +9 −0 Rakefile
  4. +10 −4 app.rb
  5. +34 −0 test/app_test.rb
View
@@ -6,3 +6,5 @@ gem 'sass', '~> 3.1.8'
gem 'flickraw', '~> 0.9.5'
gem 'fb_graph', '~> 2.4.7'
gem 'rmagick', '~> 2.13.1'
+gem 'rack-test', '~> 0.6.1'
+gem 'rake', '~> 0.9.2'
View
@@ -25,6 +25,9 @@ GEM
rack (>= 1.1)
rack-protection (1.2.0)
rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rake (0.9.2.2)
rmagick (2.13.1)
sass (3.1.15)
sinatra (1.3.2)
@@ -41,6 +44,8 @@ DEPENDENCIES
fb_graph (~> 2.4.7)
flickraw (~> 0.9.5)
haml (~> 3.1.3)
+ rack-test (~> 0.6.1)
+ rake (~> 0.9.2)
rmagick (~> 2.13.1)
sass (~> 3.1.8)
sinatra (~> 1.3.0)
View
@@ -0,0 +1,9 @@
+require 'rake/testtask'
+
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/*_test.rb'
+ test.verbose = true
+end
+
+task default: :test
View
14 app.rb
@@ -14,10 +14,10 @@
configure do
set :public_folder, Proc.new { File.join(root, "static") }
- FlickRaw.api_key = ENV['FLICKR_API_KEY']
- FlickRaw.shared_secret = ENV['FLICKR_SECRET']
- flickr.access_token = ENV['FLICKR_ACCESS_TOKEN']
- flickr.access_secret = ENV['FLICKR_ACCESS_SECRET']
+ set :flickr_api_key, ENV['FLICKR_API_KEY']
+ set :flickr_secret, ENV['FLICKR_SECRET']
+ set :flickr_access_token, ENV['FLICKR_ACCESS_TOKEN']
+ set :flickr_access_secret, ENV['FLICKR_ACCESS_SECRET']
set :fb_app_id, ENV['FB_APP_ID']
set :fb_app_secret, ENV['FB_APP_SECRET']
@@ -37,6 +37,12 @@
photo = add_logo(file_name, logo)
photo.write(file_name)
+
+ FlickRaw.api_key = settings.flickr_api_key
+ FlickRaw.shared_secret = settings.flickr_secret
+ flickr.access_token = settings.flickr_access_token
+ flickr.access_secret = settings.flickr_access_secret
+
photo_id = flickr.upload_photo file_name, :is_public => false
redirect "/show/#{photo_id}"
View
@@ -0,0 +1,34 @@
+require './app'
+require 'test/unit'
+require 'rack/test'
+
+class AppTest < Test::Unit::TestCase
+ include Rack::Test::Methods
+
+ def app
+ Sinatra::Application
+ end
+
+ def test_root_should_present_the_submit_form
+ get '/'
+ assert last_response.ok?
+ assert_match /Add the campaign logo to your photo/, last_response.body
+ end
+
+ def test_upload_should_redirect_back_to_root_without_photo
+ post '/upload', photo: nil
+ follow_redirect!
+
+ assert_equal "http://example.org/", last_request.url
+ assert last_response.ok?
+ end
+
+ def test_upload_should_redirect_back_to_root_without_tempfile
+ post '/upload', photo: { tempfile: nil }
+ follow_redirect!
+
+ assert_equal "http://example.org/", last_request.url
+ assert last_response.ok?
+ end
+
+end

0 comments on commit 6ba647b

Please sign in to comment.