lawrencepit-remarkable_paperclip 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
|
|
1
|
+
module Remarkable
|
2
|
+
module Paperclip
|
3
|
+
module Matchers
|
4
|
+
class AllowAttachmentContentTypeForMatcher < Remarkable::ActiveRecord::Base
|
5
|
+
arguments :attribute
|
6
|
+
|
7
|
+
optional :in, :splat => true
|
8
|
+
|
9
|
+
assertions :is_valid?
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def is_valid?
|
14
|
+
@options[:in].each do |value|
|
15
|
+
return false, :value => value.inspect unless allow?(value)
|
16
|
+
end
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def interpolation_options
|
21
|
+
{ :in => array_to_sentence(@options[:in].map{|i| i.inspect}) }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def allow?(content_types)
|
27
|
+
content_types.all? do |content_type|
|
28
|
+
file = StringIO.new
|
29
|
+
file.content_type = content_type
|
30
|
+
attachment = @subject.attachment_for(@attribute)
|
31
|
+
attachment.assign(file)
|
32
|
+
attachment.errors[:content_type].nil?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def allow_attachment_content_type_for(attribute, *args, &block)
|
39
|
+
options = args.extract_options!
|
40
|
+
AllowAttachmentContentTypeForMatcher.new(attribute, options.merge!(:in => args), &block).spec(self)
|
41
|
+
end
|
42
|
+
alias_method :validate_attachment_content_type, :allow_attachment_content_type_for
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -24,11 +24,11 @@ module Remarkable
|
|
24
24
|
actuals = attachment_definition[:styles].clone
|
25
25
|
match = @options[:styles].all? do |key, value|
|
26
26
|
actual = actuals.delete(key)
|
27
|
-
|
27
|
+
value == actual || value == case actual
|
28
28
|
when Hash then actual[:geometry]
|
29
29
|
when Array then actual[0]
|
30
30
|
else actual
|
31
|
-
end
|
31
|
+
end
|
32
32
|
end
|
33
33
|
return (match && actuals.size == 0),
|
34
34
|
:styles => @options[:styles].inspect, :actual => attachment_definition[:styles].inspect
|
data/lib/remarkable_paperclip.rb
CHANGED
@@ -2,7 +2,7 @@ require 'paperclip/extension'
|
|
2
2
|
require 'matchers/have_attached_file_matcher'
|
3
3
|
require 'matchers/validate_attachment_size_matcher'
|
4
4
|
require 'matchers/validate_attachment_presence_matcher'
|
5
|
-
require 'matchers/
|
5
|
+
require 'matchers/allow_attachment_content_type_for_matcher'
|
6
6
|
|
7
7
|
if defined?(Spec::Rails)
|
8
8
|
Remarkable.include_matchers!(Remarkable::Paperclip, Spec::Rails::Example::ModelExampleGroup)
|
data/locale/en.yml
CHANGED
@@ -31,13 +31,7 @@ en:
|
|
31
31
|
description: "validate attachment presence of attached file {{attribute}}"
|
32
32
|
expectations:
|
33
33
|
invalid_when_not_present: "{{subject_name}} to be invalid when attached file {{attribute}} is not present"
|
34
|
-
|
35
|
-
description: "
|
34
|
+
allow_attachment_content_type_for:
|
35
|
+
description: "allow {{in}} as content type for attachment {{attribute}}"
|
36
36
|
expectations:
|
37
|
-
|
38
|
-
rejects_match: "{{subject_name}} to reject content types {{rejects}} for attached file {{attribute}}"
|
39
|
-
optionals:
|
40
|
-
allows:
|
41
|
-
positive: "allowing {{inspect}}"
|
42
|
-
rejects:
|
43
|
-
positive: "rejecting {{inspect}}"
|
37
|
+
is_valid: "{{subject_name}} to be valid when content type for attachment {{attribute}} is set to {{value}}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lawrencepit-remarkable_paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lawrence Pit
|
@@ -30,7 +30,7 @@ files:
|
|
30
30
|
- lib/matchers/have_attached_file_matcher.rb
|
31
31
|
- lib/matchers/validate_attachment_presence_matcher.rb
|
32
32
|
- lib/matchers/validate_attachment_size_matcher.rb
|
33
|
-
- lib/matchers/
|
33
|
+
- lib/matchers/allow_attachment_content_type_for_matcher.rb
|
34
34
|
has_rdoc: false
|
35
35
|
homepage: http://github.com/lawrencepit/remarkable_paperclip
|
36
36
|
post_install_message:
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Paperclip
|
3
|
-
module Matchers
|
4
|
-
class ValidateAttachmentContentTypeMatcher < Remarkable::ActiveRecord::Base
|
5
|
-
arguments :attribute
|
6
|
-
|
7
|
-
optionals :allows, :rejects
|
8
|
-
|
9
|
-
assertions :allows_match?, :rejects_match?
|
10
|
-
|
11
|
-
protected
|
12
|
-
|
13
|
-
def allows_match?
|
14
|
-
return true unless @options.key?(:allows)
|
15
|
-
allow?(@options[:allows])
|
16
|
-
end
|
17
|
-
|
18
|
-
def rejects_match?
|
19
|
-
return true unless @options.key?(:rejects)
|
20
|
-
!allow?(@options[:rejects])
|
21
|
-
end
|
22
|
-
|
23
|
-
def interpolation_options
|
24
|
-
{ :allows => @options[:allows].inspect, :rejects => @options[:rejects].inspect }
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def allow?(content_types)
|
30
|
-
content_types.all? do |content_type|
|
31
|
-
file = StringIO.new
|
32
|
-
file.content_type = content_type
|
33
|
-
attachment = @subject.attachment_for(@attribute)
|
34
|
-
attachment.assign(file)
|
35
|
-
attachment.errors[:content_type].nil?
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def validate_attachment_content_type(*args)
|
42
|
-
ValidateAttachmentContentTypeMatcher.new(*args).spec(self)
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|