Permalink
Browse files

Add basic integration test using Cucumber

This test will generate a basic Rails application, include Paperclip
into Gemfile, and call basic `has_attached_file` in the model. This will
make sure that we're not messing up any of the configuration and
integration for our gem and the Rails framework.
  • Loading branch information...
1 parent ae781ac commit 3131601f2724814efc00718443db7a9ef1b7fb26 @sikachu sikachu committed Aug 5, 2011
View
@@ -4,7 +4,9 @@ rvm:
- ree
- rbx-2.0
-script: "bundle exec rake clean test"
+before_script: "sudo ntpdate -ub ntp.ubuntu.com pool.ntp.org; true"
+script: "bundle exec rake clean test cucumber"
+
gemfile:
- gemfiles/rails2.gemfile
- gemfiles/rails3.gemfile
View
@@ -1,11 +1,14 @@
appraise "rails2" do
gem "rails", "~> 2.3.14"
+ gem "paperclip", :path => "../"
end
appraise "rails3" do
gem "rails", "~> 3.0.10"
+ gem "paperclip", :path => "../"
end
appraise "rails3_1" do
gem "rails", "~> 3.1.0"
+ gem "paperclip", :path => "../"
end
View
@@ -2,6 +2,7 @@ source "http://rubygems.org"
gem "activerecord", :require => "active_record"
gem "appraisal"
+gem "aruba"
gem "aws-s3", :require => "aws/s3"
gem "bundler"
gem "cocaine", "~>0.2"
@@ -11,11 +12,11 @@ gem "mime-types"
gem "mocha"
gem "rake"
gem "rdoc", :require => false
+gem "capybara"
+gem "cucumber", "~> 1.0.0"
gem "shoulda"
gem "sqlite3", "~>1.3.4"
-
-# This is for Rails 3.1
-gem "sprockets", "~> 2.0.0.beta.13", :require => false
+gem "fakeweb", :require => false
# gem "ruby-debug", :platform => :ruby_18
# gem "ruby-debug19", :platform => :ruby_19
View
@@ -1,100 +0,0 @@
-GEM
- remote: http://rubygems.org/
- specs:
- activerecord (2.3.12)
- activesupport (= 2.3.12)
- activesupport (2.3.12)
- appraisal (0.3.5)
- aruba (~> 0.3.6)
- bundler
- rake
- aruba (0.3.7)
- childprocess (>= 0.1.9)
- cucumber (>= 0.10.5)
- rspec (>= 2.6.0)
- aws-s3 (0.6.2)
- builder
- mime-types
- xml-simple
- bouncy-castle-java (1.5.0146.1)
- builder (3.0.0)
- childprocess (0.1.9)
- ffi (~> 1.0.6)
- cocaine (0.2.0)
- cucumber (0.10.5)
- builder (>= 2.1.2)
- diff-lcs (>= 1.1.2)
- gherkin (~> 2.4.0)
- json (>= 1.4.6)
- term-ansicolor (>= 1.0.5)
- diff-lcs (1.1.2)
- excon (0.6.3)
- ffi (1.0.9)
- ffi (1.0.9-java)
- fog (0.8.2)
- builder
- excon (~> 0.6.1)
- formatador (>= 0.1.3)
- json
- mime-types
- net-ssh (>= 2.1.3)
- nokogiri (>= 1.4.4)
- ruby-hmac
- formatador (0.1.4)
- gherkin (2.4.5)
- json (>= 1.4.6)
- gherkin (2.4.5-java)
- json (>= 1.4.6)
- hike (1.2.0)
- jruby-openssl (0.7.4)
- bouncy-castle-java
- json (1.5.3)
- json (1.5.3-java)
- mime-types (1.16)
- mocha (0.9.12)
- net-ssh (2.1.4)
- nokogiri (1.4.4)
- nokogiri (1.4.4-java)
- weakling (>= 0.0.3)
- rack (1.3.2)
- rake (0.9.2)
- rdoc (3.8)
- rspec (2.6.0)
- rspec-core (~> 2.6.0)
- rspec-expectations (~> 2.6.0)
- rspec-mocks (~> 2.6.0)
- rspec-core (2.6.4)
- rspec-expectations (2.6.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.6.0)
- ruby-hmac (0.4.0)
- shoulda (2.11.3)
- sprockets (2.0.0.beta.13)
- hike (~> 1.2)
- rack (~> 1.0)
- tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.4)
- term-ansicolor (1.0.5)
- tilt (1.3.2)
- weakling (0.0.4-java)
- xml-simple (1.0.16)
-
-PLATFORMS
- java
- ruby
-
-DEPENDENCIES
- activerecord
- appraisal
- aws-s3
- bundler
- cocaine (~> 0.2)
- fog
- jruby-openssl
- mime-types
- mocha
- rake
- rdoc
- shoulda
- sprockets (~> 2.0.0.beta.13)
- sqlite3 (~> 1.3.4)
View
@@ -5,6 +5,7 @@ require 'bundler/setup'
require 'rake'
require 'rake/testtask'
require 'rdoc/task'
+require 'cucumber/rake/task'
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require 'paperclip'
@@ -14,7 +15,7 @@ task :default => [:clean, 'appraisal:install', :all]
desc 'Test the paperclip plugin under all supported Rails versions.'
task :all do |t|
- exec('rake appraisal test')
+ exec('rake appraisal test cucumber')
end
desc 'Test the paperclip plugin.'
@@ -24,6 +25,11 @@ Rake::TestTask.new(:test) do |t|
t.verbose = true
end
+desc 'Run integration test'
+Cucumber::Rake::Task.new do |t|
+ t.cucumber_opts = %w{--format progress}
+end
+
desc 'Start an IRB session with all necessary files required.'
task :shell do |t|
chdir File.dirname(__FILE__)
View
@@ -1,17 +0,0 @@
-Feature: Running paperclip in a Rails app
-
- Scenario: Basic utilization
- Given I have a rails application
- And I save the following as "app/models/user.rb"
- """
- class User < ActiveRecord::Base
- has_attached_file :avatar
- end
- """
- When I visit /users/new
- And I fill in "user_name" with "something"
- And I attach the file "test/fixtures/5k.png" to "user_avatar"
- And I press "Submit"
- Then I should see "Name: something"
- And I should see an image with a path of "/system/avatars/1/original/5k.png"
- And the file at "/system/avatars/1/original/5k.png" is the same as "test/fixtures/5k.png"
@@ -0,0 +1,46 @@
+Feature: Rails integration
+
+ Background:
+ Given I generate a new rails application
+ And I run a rails generator to generate a "User" scaffold with "name:string"
+ And I run a paperclip generator to add a paperclip "attachment" to the "User" model
+ And I run a migration
+ And I update my new user view to include the file upload field
+ And I update my user view to include the attachment
+
+ Scenario: Filesystem integration test
+ Given I add this snippet to the User model:
+ """
+ has_attached_file :attachment
+ """
+ And I start the rails application
+ When I go to the new user page
+ And I fill in "Name" with "something"
+ And I attach the file "test/fixtures/5k.png" to "Attachment"
+ And I press "Submit"
+ Then I should see "Name: something"
+ And I should see an image with a path of "/system/attachments/1/original/5k.png"
+ And the file at "/system/attachments/1/original/5k.png" should be the same as "test/fixtures/5k.png"
+
+ Scenario: S3 Integration test
+ Given I add this snippet to the User model:
+ """
+ has_attached_file :attachment,
+ :storage => :s3,
+ :path => "/:attachment/:id/:style/:filename",
+ :s3_credentials => Rails.root.join("config/s3.yml")
+ """
+ And I write to "config/s3.yml" with:
+ """
+ bucket: paperclip
+ access_key_id: access_key
+ secret_access_key: secret_key
+ """
+ And I start the rails application
+ When I go to the new user page
+ And I fill in "Name" with "something"
+ And I attach the file "test/fixtures/5k.png" to "Attachment" on S3
+ And I press "Submit"
+ Then I should see "Name: something"
+ And I should see an image with a path of "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png"
+ And the file at "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png" should be uploaded to S3
View
@@ -1,27 +0,0 @@
-Feature: Running paperclip in a Rails app using basic S3 support
-
- Scenario: Basic utilization
- Given I have a rails application
- And I save the following as "app/models/user.rb"
- """
- class User < ActiveRecord::Base
- has_attached_file :avatar,
- :storage => :s3,
- :path => "/:attachment/:id/:style/:filename",
- :s3_credentials => Rails.root.join("config/s3.yml")
- end
- """
- And I validate my S3 credentials
- And I save the following as "config/s3.yml"
- """
- bucket: <%= ENV['PAPERCLIP_TEST_BUCKET'] || 'paperclip' %>
- access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
- secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
- """
- When I visit /users/new
- And I fill in "user_name" with "something"
- And I attach the file "test/fixtures/5k.png" to "user_avatar"
- And I press "Submit"
- Then I should see "Name: something"
- And I should see an image with a path of "http://s3.amazonaws.com/paperclip/avatars/1/original/5k.png"
- And the file at "http://s3.amazonaws.com/paperclip/avatars/1/original/5k.png" is the same as "test/fixtures/5k.png"
@@ -10,5 +10,6 @@
visit(web_file)
page.body
end
+ actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
actual.should == expected
end
Oops, something went wrong.

0 comments on commit 3131601

Please sign in to comment.