Skip to content

Commit

Permalink
add RSpec (#71)
Browse files Browse the repository at this point in the history
* ignore ruby version

this will be up to the developer to decide.

* add and configure RSpec

* add basic specs for the functionality

just test that the fields are created.

* add testing section to README
  • Loading branch information
tilsammans committed Aug 10, 2016
1 parent 7eb32a3 commit b87a92b
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
mongoid-paperclip-*.gem
.*swp
.*swo
.ruby-version
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Use the gemspec for all dependencies.
gemspec
75 changes: 75 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions lib/mongoid-paperclip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'mongoid_paperclip'
2 changes: 1 addition & 1 deletion lib/mongoid_paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def self.included(base)
end

module ClassMethods

##
# Adds after_commit
def after_commit(*args, &block)
Expand Down
5 changes: 5 additions & 0 deletions mongoid-paperclip.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions spec/config/mongoid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test:
clients:
default:
database: mongoid-paperclip
hosts:
- localhost:27017
29 changes: 29 additions & 0 deletions spec/mongoid-paperclip_spec.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Binary file added spec/support/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b87a92b

Please sign in to comment.