diff --git a/.gitignore b/.gitignore index ff5b168..78478c7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ mongoid-paperclip-*.gem .*swp .*swo +.ruby-version diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4e1e0d2 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..28ebca1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Use the gemspec for all dependencies. +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..c4198a6 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,75 @@ +PATH + remote: . + specs: + mongoid-paperclip (0.0.10) + mongoid + paperclip (>= 2.3.6, != 4.3.0) + +GEM + remote: https://rubygems.org/ + specs: + activemodel (4.2.6) + activesupport (= 4.2.6) + builder (~> 3.1) + activesupport (4.2.6) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + bson (4.1.1) + builder (3.2.2) + climate_control (0.0.3) + activesupport (>= 3.0) + cocaine (0.5.8) + climate_control (>= 0.0.3, < 1.0) + diff-lcs (1.2.5) + i18n (0.7.0) + json (1.8.3) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mimemagic (0.3.2) + minitest (5.9.0) + mongo (2.2.5) + bson (~> 4.0) + mongoid (5.1.3) + activemodel (~> 4.0) + mongo (~> 2.1) + origin (~> 2.2) + tzinfo (>= 0.3.37) + origin (2.2.0) + paperclip (5.0.0) + activemodel (>= 4.2.0) + activesupport (>= 4.2.0) + cocaine (~> 0.5.5) + mime-types + mimemagic (~> 0.3.0) + rake (11.2.2) + rspec (3.5.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-core (3.5.2) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) + thread_safe (0.3.5) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + mongoid-paperclip! + rake + rspec + +BUNDLED WITH + 1.12.5 diff --git a/README.md b/README.md index 8383ea0..f5d103c 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,16 @@ end @user.update_attributes({ ... :pictures => [...] }) ``` +## Testing + +If you want to help develop this plugin, clone the repo and bundle to get all dependencies. + +Then to run the tests: + +``` +rspec +``` + ## There you go Quite a lot of people have been looking for a solution to use Paperclip with Mongoid so I hope this helps! diff --git a/lib/mongoid-paperclip.rb b/lib/mongoid-paperclip.rb new file mode 100644 index 0000000..6999810 --- /dev/null +++ b/lib/mongoid-paperclip.rb @@ -0,0 +1 @@ +require 'mongoid_paperclip' diff --git a/lib/mongoid_paperclip.rb b/lib/mongoid_paperclip.rb index 2d8e4f7..5bd1886 100644 --- a/lib/mongoid_paperclip.rb +++ b/lib/mongoid_paperclip.rb @@ -62,7 +62,7 @@ def self.included(base) end module ClassMethods - + ## # Adds after_commit def after_commit(*args, &block) diff --git a/mongoid-paperclip.gemspec b/mongoid-paperclip.gemspec index ea97828..b320d5c 100644 --- a/mongoid-paperclip.gemspec +++ b/mongoid-paperclip.gemspec @@ -16,5 +16,10 @@ Gem::Specification.new do |gem| gem.test_files = %x[git ls-files -- {spec}/*].split("\n") gem.require_path = 'lib' + gem.add_dependency 'mongoid' gem.add_dependency 'paperclip', ['>= 2.3.6', '!=4.3.0'] + + gem.add_development_dependency 'bundler' + gem.add_development_dependency 'rake' + gem.add_development_dependency 'rspec' end diff --git a/spec/config/mongoid.yml b/spec/config/mongoid.yml new file mode 100644 index 0000000..8e1a2db --- /dev/null +++ b/spec/config/mongoid.yml @@ -0,0 +1,6 @@ +test: + clients: + default: + database: mongoid-paperclip + hosts: + - localhost:27017 diff --git a/spec/mongoid-paperclip_spec.rb b/spec/mongoid-paperclip_spec.rb new file mode 100644 index 0000000..b6df183 --- /dev/null +++ b/spec/mongoid-paperclip_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +RSpec.describe Mongoid::Paperclip, type: :unit do + let(:user) { User.create } + + before do + user.update avatar: File.new('spec/support/avatar.png', 'rb') + end + + it "stores file_name" do + expect(user.avatar_file_name).to eq("avatar.png") + end + + it "stores content_type" do + expect(user.avatar_content_type).to eq("image/png") + end + + it "stores file_size" do + expect(user.avatar_file_size).to eq(357) + end + + it "stores updated_at" do + expect(user.avatar_updated_at).to be_present + end + + it "stores fingerprint" do + expect(user.avatar_fingerprint).to eq("2584a801e588b3fcf4aa074efff77e30") + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..d1850f5 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,20 @@ +require 'rspec' +require 'mongoid' +require 'mongoid-paperclip' + +ENV['MONGOID_ENV'] = 'test' +Mongoid.load!('./spec/config/mongoid.yml') + +RSpec.configure do |config| + config.before(:each) do + Mongoid.purge! + end +end + +class User + include Mongoid::Document + include Mongoid::Paperclip + + has_mongoid_attached_file :avatar + validates_attachment_file_name :avatar, matches: [/image/] +end diff --git a/spec/support/avatar.png b/spec/support/avatar.png new file mode 100644 index 0000000..0147f6c Binary files /dev/null and b/spec/support/avatar.png differ