1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
Given /^an uploader class that uses the '(.*?)' storage$/ do |kind|
@klass = Class.new(CarrierWave::Uploader::Base)
@klass.storage = kind.to_sym
end
Given /^an instance of that class$/ do
@uploader = @klass.new
end
Given /^a processor method named :upcase$/ do
@klass.class_eval do
define_method(:upcase) do
content = File.read(current_path)
File.open(current_path, 'w') { |f| f.write content.upcase }
end
end
end
Then /^the contents of the file should be '(.*?)'$/ do |contents|
@uploader.read.chomp.should == contents
end
Given /^that the uploader reverses the filename$/ do
@klass.class_eval do
def filename
super.reverse unless super.blank?
end
end
end
Given /^that the uploader has the filename overridden to '(.*?)'$/ do |filename|
@klass.class_eval do
define_method(:filename) do
filename
end
end
end
Given /^that the uploader has the store_dir overridden to '(.*?)'$/ do |store_dir|
@klass.class_eval do
define_method(:store_dir) do
file_path(store_dir)
end
end
end
Given /^that the version '(.*?)' has the store_dir overridden to '(.*?)'$/ do |version, store_dir|
@klass.versions[version.to_sym].class_eval do
define_method(:store_dir) do
file_path(store_dir)
end
end
end
Given /^that the uploader class has a version named '([^\']+)'$/ do |name|
@klass.version(name)
end
Given /^that the uploader class has a version named '([^\']+)' which process '([a-zA-Z0-9\_\?!]*)'$/ do |name, processor_name|
@klass.version(name) do
process processor_name.to_sym
end
end
Given /^that the uploader class has a version named '([^\']+)' which is based on version '(.*?)'$/ do |name, based_version_name|
@klass.version(name, {:from_version => based_version_name.to_sym})
end
Given /^yo dawg, I put a version called '(.*?)' in your version called '(.*?)'$/ do |v2, v1|
@klass.version(v1) do
version(v2)
end
end
Given /^the class has a method called 'reverse' that reverses the contents of a file$/ do
@klass.class_eval do
def reverse
text = File.read(current_path)
File.open(current_path, 'w') { |f| f.write(text.reverse) }
end
end
end
Given /^the class will process '([a-zA-Z0-9\_\?!]*)'$/ do |name|
@klass.process name.to_sym
end
Then /^the uploader should have '(.*?)' as its current path$/ do |path|
@uploader.current_path.should == file_path(path)
end
Then /^the uploader should have the url '(.*?)'$/ do |url|
@uploader.url.should == url
end
Then /^the uploader's version '(.*?)' should have the url '(.*?)'$/ do |version, url|
@uploader.versions[version.to_sym].url.should == url
end
Then /^the uploader's nested version '(.*?)' nested in '(.*?)' should have the url '(.*?)'$/ do |v2, v1, url|
@uploader.versions[v1.to_sym].versions[v2.to_sym].url.should == url
end
|