diff options
| author | hukl <contact@smyck.org> | 2009-04-24 11:43:08 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-04-25 14:55:27 +0200 |
| commit | cf1b60e0cfa7d1a8f4a80d686649cc12e73a634e (patch) | |
| tree | b68bd845d290ce968892c4532bcff52083925834 /vendor/plugins/paperclip/test/helper.rb | |
| parent | b2b78c06074046bd73cc3408a29386a976f0469c (diff) | |
Integrated basic Asset upload functionality. You can upload files now and use their url in pages.
Diffstat (limited to 'vendor/plugins/paperclip/test/helper.rb')
| -rw-r--r-- | vendor/plugins/paperclip/test/helper.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/vendor/plugins/paperclip/test/helper.rb b/vendor/plugins/paperclip/test/helper.rb new file mode 100644 index 0000000..3e7e6a1 --- /dev/null +++ b/vendor/plugins/paperclip/test/helper.rb | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | require 'rubygems' | ||
| 2 | require 'test/unit' | ||
| 3 | gem 'thoughtbot-shoulda', ">= 2.9.0" | ||
| 4 | require 'shoulda' | ||
| 5 | require 'mocha' | ||
| 6 | require 'tempfile' | ||
| 7 | |||
| 8 | gem 'sqlite3-ruby' | ||
| 9 | |||
| 10 | require 'active_record' | ||
| 11 | require 'active_support' | ||
| 12 | begin | ||
| 13 | require 'ruby-debug' | ||
| 14 | rescue LoadError | ||
| 15 | puts "ruby-debug not loaded" | ||
| 16 | end | ||
| 17 | |||
| 18 | ROOT = File.join(File.dirname(__FILE__), '..') | ||
| 19 | RAILS_ROOT = ROOT | ||
| 20 | |||
| 21 | $LOAD_PATH << File.join(ROOT, 'lib') | ||
| 22 | $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip') | ||
| 23 | |||
| 24 | require File.join(ROOT, 'lib', 'paperclip.rb') | ||
| 25 | |||
| 26 | require 'shoulda_macros/paperclip' | ||
| 27 | |||
| 28 | ENV['RAILS_ENV'] ||= 'test' | ||
| 29 | |||
| 30 | FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") | ||
| 31 | config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) | ||
| 32 | ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") | ||
| 33 | ActiveRecord::Base.establish_connection(config['test']) | ||
| 34 | |||
| 35 | def reset_class class_name | ||
| 36 | ActiveRecord::Base.send(:include, Paperclip) | ||
| 37 | Object.send(:remove_const, class_name) rescue nil | ||
| 38 | klass = Object.const_set(class_name, Class.new(ActiveRecord::Base)) | ||
| 39 | klass.class_eval{ include Paperclip } | ||
| 40 | klass | ||
| 41 | end | ||
| 42 | |||
| 43 | def reset_table table_name, &block | ||
| 44 | block ||= lambda{ true } | ||
| 45 | ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block | ||
| 46 | end | ||
| 47 | |||
| 48 | def modify_table table_name, &block | ||
| 49 | ActiveRecord::Base.connection.change_table :dummies, &block | ||
| 50 | end | ||
| 51 | |||
| 52 | def rebuild_model options = {} | ||
| 53 | ActiveRecord::Base.connection.create_table :dummies, :force => true do |table| | ||
| 54 | table.column :other, :string | ||
| 55 | table.column :avatar_file_name, :string | ||
| 56 | table.column :avatar_content_type, :string | ||
| 57 | table.column :avatar_file_size, :integer | ||
| 58 | table.column :avatar_updated_at, :datetime | ||
| 59 | end | ||
| 60 | rebuild_class options | ||
| 61 | end | ||
| 62 | |||
| 63 | def rebuild_class options = {} | ||
| 64 | ActiveRecord::Base.send(:include, Paperclip) | ||
| 65 | Object.send(:remove_const, "Dummy") rescue nil | ||
| 66 | Object.const_set("Dummy", Class.new(ActiveRecord::Base)) | ||
| 67 | Dummy.class_eval do | ||
| 68 | include Paperclip | ||
| 69 | has_attached_file :avatar, options | ||
| 70 | end | ||
| 71 | end | ||
| 72 | |||
| 73 | def temporary_rails_env(new_env) | ||
| 74 | old_env = defined?(RAILS_ENV) ? RAILS_ENV : nil | ||
| 75 | silence_warnings do | ||
| 76 | Object.const_set("RAILS_ENV", new_env) | ||
| 77 | end | ||
| 78 | yield | ||
| 79 | silence_warnings do | ||
| 80 | Object.const_set("RAILS_ENV", old_env) | ||
| 81 | end | ||
| 82 | end | ||
