Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

81 lines (66 sloc) 2.387 kb
require './test/helper'
require 'rails/generators'
require 'generators/paperclip/paperclip_generator'
class GeneratorTest < Rails::Generators::TestCase
tests PaperclipGenerator
destination File.expand_path("../tmp", File.dirname(__FILE__))
setup :prepare_destination
context 'running migration' do
context 'with single attachment name' do
setup do
run_generator %w(user avatar)
end
should 'create a correct migration file' do
assert_migration 'db/migrate/add_attachment_avatar_to_users.rb' do |migration|
assert_match /class AddAttachmentAvatarToUsers/, migration
assert_class_method :up, migration do |up|
expected = <<-migration
change_table :users do |t|
t.has_attached_file :avatar
end
migration
assert_equal expected.squish, up.squish
end
assert_class_method :down, migration do |down|
expected = <<-migration
drop_attached_file :users, :avatar
migration
assert_equal expected.squish, down.squish
end
end
end
end
context 'with multiple attachment names' do
setup do
run_generator %w(user avatar photo)
end
should 'create a correct migration file' do
assert_migration 'db/migrate/add_attachment_avatar_photo_to_users.rb' do |migration|
assert_match /class AddAttachmentAvatarPhotoToUsers/, migration
assert_class_method :up, migration do |up|
expected = <<-migration
change_table :users do |t|
t.has_attached_file :avatar
t.has_attached_file :photo
end
migration
assert_equal expected.squish, up.squish
end
assert_class_method :down, migration do |down|
expected = <<-migration
drop_attached_file :users, :avatar
drop_attached_file :users, :photo
migration
assert_equal expected.squish, down.squish
end
end
end
end
context 'without required arguments' do
should 'not create the migration' do
silence_stream(STDERR) { run_generator %w() }
assert_no_migration 'db/migrate/add_attachment_avatar_to_users.rb'
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.