riot-carrierwave 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Arthur Chiu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # riot-carrierwave
2
+
3
+ Riot macros for Carrierwave.
4
+
5
+ These macros have been mostly converted over from the included rspec matchers included in carrierwave.
6
+
7
+ ## Examples
8
+
9
+ context "my Uploader" do
10
+ setup do
11
+ Uploader.enable_processing = true
12
+ @uploader = Uploader.new
13
+ @uploader.store! File.open('picture.jpg')
14
+ @uploader
15
+ end
16
+
17
+ asserts_topic.has_dimensions :equal, 30,30
18
+ asserts_topic.has_dimensions :no_larger_than, 30, 30
19
+ asserts_topic.has_dimensions :no_smaller_than, 20, 20
20
+ asserts_topic.has_dimensions :larger_than, 30, 30
21
+ asserts_topic.has_dimensions :smaller_than, 30, 30
22
+ asserts_topic.has_permission 0777
23
+ asserts_topic.identical_to 'picture.jpg'
24
+
25
+ end
26
+
27
+ ## Note on Patches/Pull Requests
28
+
29
+ * Fork the project.
30
+ * Make your feature addition or bug fix.
31
+ * Add tests for it. This is important so I don't break it in a
32
+ future version unintentionally.
33
+ * Commit, do not mess with rakefile, version, or history.
34
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
35
+ * Send me a pull request. Bonus points for topic branches.
36
+
37
+ ## Copyright
38
+
39
+ Copyright (c) 2010 Arthur Chiu. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "riot-carrierwave"
8
+ gem.summary = %Q{riot macros for carrierwave}
9
+ gem.description = %Q{riot macros for carrierwave testing}
10
+ gem.email = "mr.arthur.chiu@gmail.com"
11
+ gem.homepage = "http://github.com/achiu/riot-carrierwave"
12
+ gem.authors = ["Arthur Chiu"]
13
+ gem.add_development_dependency "riot", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/*_test.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "riot-carrierwave #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,4 @@
1
+ require 'riot'
2
+ require 'carrierwave'
3
+
4
+ Dir[File.dirname(__FILE__) + '/riot-carrierwave/*.rb'].each {|file| require file }
@@ -0,0 +1,32 @@
1
+ module RiotCarrierwave
2
+ class HasDimensionsAssertion < Riot::AssertionMacro
3
+ register :has_dimensions
4
+
5
+ def evaluate(model, type, width, height)
6
+ image = RiotCarrierwave::ImageLoader.load_image(model.current_path)
7
+ if image and compare(type, image, width, height)
8
+ pass "#{model.class.name} has dimensions #{type} width #{width}px and height #{height}px"
9
+ else
10
+ fail "expected #{model.class.name} to have dimensions #{type} width #{width}px and height #{height}px"
11
+ end
12
+ end
13
+
14
+ def compare(type, image, width,height)
15
+ case type
16
+ when :no_larger_than
17
+ width >= image.width and height >= image.height
18
+ when :no_smaller_than
19
+ width <= image.width and height <= image.height
20
+ when :larger_than
21
+ width < image.width and height < image.height
22
+ when :smaller_than
23
+ width > image.width and height > image.height
24
+ when :equal
25
+ width == image.width and height == image.height
26
+ else
27
+ false
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ module RiotCarrierwave
2
+ class HasPermissionAssertion < Riot::AssertionMacro
3
+ register :has_permission
4
+
5
+ def evaluate(model, permission)
6
+ if model and ((File.stat(model.path).mode & 0777) == permission)
7
+ pass("#{model.class.name} has permission of #{permission.to_s(8)}")
8
+ else
9
+ fail("expected #{model.class.name} to have permission of #{permission.to_s(8)}")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module RiotCarrierwave
2
+ class IdenticalToAssertion < Riot::AssertionMacro
3
+ register :identical_to
4
+
5
+ def evaluate(model, file)
6
+ if model and FileUtils.identical?(model.path,file)
7
+ pass("#{model.path} is identical to #{file}")
8
+ else
9
+ fail("expected #{model.path} to be identical to #{file}")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ module RiotCarrierwave
2
+
3
+ class ImageLoader # :nodoc:
4
+ def self.load_image(filename)
5
+ if defined? MiniMagick
6
+ RiotCarrierwave::MiniMagickWrapper.new(filename)
7
+ else
8
+ unless defined? Magick
9
+ begin
10
+ require 'rmagick'
11
+ rescue LoadError
12
+ require 'RMagick'
13
+ rescue LoadError
14
+ puts "WARNING: Failed to require rmagick, image processing may fail!"
15
+ end
16
+ end
17
+ RiotCarrierwave::MagickWrapper.new(filename)
18
+ end
19
+ end
20
+ end
21
+
22
+ class MagickWrapper # :nodoc:
23
+ attr_reader :image
24
+
25
+ def width; image.columns; end
26
+ def height; image.rows; end
27
+
28
+ def initialize(filename)
29
+ @image = ::Magick::Image.read(filename).first
30
+ end
31
+ end
32
+
33
+ class MiniMagickWrapper # :nodoc:
34
+ attr_reader :image
35
+
36
+ def width; image[:width]; end
37
+
38
+ def height; image[:height]; end
39
+
40
+ def initialize(filename)
41
+ @image = ::MiniMagick::Image.from_file(filename)
42
+ end
43
+ end
44
+ end
Binary file
Binary file
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__),'teststrap')
2
+
3
+ context "has_dimensions macro" do
4
+ setup do
5
+ Uploader.enable_processing = true
6
+ @uploader = Uploader.new
7
+ @uploader.store! File.open(fixture('fail.jpg'))
8
+ @uploader
9
+ end
10
+
11
+ asserts "passes when the dimensions equal matches" do
12
+ RiotCarrierwave::HasDimensionsAssertion.new.evaluate(topic, :equal, 600,396).first
13
+ end.equals :pass
14
+
15
+ asserts "passes when the dimensions no larger than matches" do
16
+ RiotCarrierwave::HasDimensionsAssertion.new.evaluate(topic, :no_larger_than, 600,396).first
17
+ end.equals :pass
18
+
19
+ asserts "passes when the dimensions no lesser than matches" do
20
+ RiotCarrierwave::HasDimensionsAssertion.new.evaluate(topic, :no_smaller_than, 600,396).first
21
+ end.equals :pass
22
+
23
+ asserts "passes when the dimensions larger than matches" do
24
+ RiotCarrierwave::HasDimensionsAssertion.new.evaluate(topic, :larger_than, 500,296).first
25
+ end.equals :pass
26
+
27
+ asserts "passes when the dimensions lesser than matches" do
28
+ RiotCarrierwave::HasDimensionsAssertion.new.evaluate(topic, :no_smaller_than, 600,396).first
29
+ end.equals :pass
30
+
31
+ asserts "returns a helpful message" do
32
+ RiotCarrierwave::HasDimensionsAssertion.new.evaluate(topic, :equal, 600,396).last
33
+ end.matches %r{Uploader has dimensions equal width 600px and height 396px}
34
+
35
+ asserts "fails when the dimensions do not match" do
36
+ RiotCarrierwave::HasDimensionsAssertion.new.evaluate(topic, :equal, 12,13).first
37
+ end.equals :fail
38
+
39
+ end
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__),'teststrap')
2
+
3
+ context "has_permission macro" do
4
+ setup do
5
+ Uploader.enable_processing = true
6
+ @uploader = Uploader.new
7
+ @uploader.store! File.open(fixture('test.jpg'))
8
+ @uploader
9
+ end
10
+
11
+ asserts "passes when the permissions matches" do
12
+ RiotCarrierwave::HasPermissionAssertion.new.evaluate(topic, 0777).first
13
+ end.equals :pass
14
+
15
+ asserts "returns a helpful message" do
16
+ RiotCarrierwave::HasPermissionAssertion.new.evaluate(topic, 0777).last
17
+ end.matches %r{Uploader has permission of 777}
18
+
19
+ asserts "fails when the permissions do not match" do
20
+ RiotCarrierwave::HasPermissionAssertion.new.evaluate(topic, 0600).first
21
+ end.equals :fail
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__),'teststrap')
2
+
3
+ context "identical_to macro" do
4
+ setup do
5
+ Uploader.enable_processing = true
6
+ @uploader = Uploader.new
7
+ @uploader.store! File.open(fixture('test.jpg'))
8
+ @uploader
9
+ end
10
+
11
+ asserts "passes when the files are identical matches" do
12
+ RiotCarrierwave::IdenticalToAssertion.new.evaluate(topic, fixture('test.jpg')).first
13
+ end.equals :pass
14
+
15
+ asserts "returns a helpful message" do
16
+ RiotCarrierwave::IdenticalToAssertion.new.evaluate(topic, fixture('test.jpg')).last
17
+ end.matches %r{is identical to #{fixture('test.jpg')}}
18
+
19
+ asserts "fails when the permissions do not match" do
20
+ RiotCarrierwave::IdenticalToAssertion.new.evaluate(topic, fixture('fail.jpg')).first
21
+ end.equals :fail
22
+
23
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'riot'
3
+ require File.join(File.dirname(__FILE__),'..','lib','riot-carrierwave')
4
+
5
+
6
+ class Uploader < CarrierWave::Uploader::Base
7
+ permissions 0777
8
+ end
9
+
10
+ def fixture(image)
11
+ File.join(File.dirname(__FILE__), 'fixtures', image)
12
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riot-carrierwave
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Arthur Chiu
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-03 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: riot
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: riot macros for carrierwave testing
36
+ email: mr.arthur.chiu@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.md
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/riot-carrierwave.rb
52
+ - lib/riot-carrierwave/has_dimensions.rb
53
+ - lib/riot-carrierwave/has_permission.rb
54
+ - lib/riot-carrierwave/identical_to.rb
55
+ - lib/riot-carrierwave/wrappers.rb
56
+ - test/fixtures/fail.jpg
57
+ - test/fixtures/test.jpg
58
+ - test/has_dimensions_test.rb
59
+ - test/has_permission_test.rb
60
+ - test/identical_to_test.rb
61
+ - test/teststrap.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/achiu/riot-carrierwave
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: riot macros for carrierwave
96
+ test_files:
97
+ - test/has_dimensions_test.rb
98
+ - test/has_permission_test.rb
99
+ - test/identical_to_test.rb
100
+ - test/teststrap.rb