Skip to content

Commit

Permalink
Add basic integration test using Cucumber
Browse files Browse the repository at this point in the history
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
sikachu committed Sep 7, 2011
1 parent ae781ac commit 3131601
Show file tree
Hide file tree
Showing 26 changed files with 425 additions and 355 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Appraisals
@@ -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
7 changes: 4 additions & 3 deletions Gemfile
Expand Up @@ -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"
Expand All @@ -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
100 changes: 0 additions & 100 deletions Gemfile.lock

This file was deleted.

8 changes: 7 additions & 1 deletion Rakefile
Expand Up @@ -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'
Expand All @@ -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.'
Expand All @@ -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__)
Expand Down
17 changes: 0 additions & 17 deletions features/basic.feature

This file was deleted.

46 changes: 46 additions & 0 deletions features/basic_integration.feature
@@ -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
27 changes: 0 additions & 27 deletions features/s3.feature

This file was deleted.

1 change: 1 addition & 0 deletions features/step_definitions/html_steps.rb
Expand Up @@ -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

0 comments on commit 3131601

Please sign in to comment.