Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
98b90bc4
Commit
98b90bc4
authored
Aug 24, 2009
by
Daniel Croak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shoulda macro and webrat step for testing paperclip on s3
parent
4beeb7a7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
cucumber/paperclip_steps.rb
+6
-0
shoulda_macros/paperclip.rb
+48
-0
No files found.
cucumber/paperclip_steps.rb
0 → 100644
View file @
98b90bc4
When
/^I attach an? "([^\"]*)" "([^\"]*)" file to an? "([^\"]*)" on S3$/
do
|
attachment
,
extension
,
model
|
stub_paperclip_s3
(
model
,
attachment
,
extension
)
attach_file
attachment
,
"features/support/paperclip/
#{
model
.
gsub
(
" "
,
"_"
).
underscore
}
/
#{
attachment
}
.
#{
extension
}
"
end
shoulda_macros/paperclip.rb
View file @
98b90bc4
...
...
@@ -60,9 +60,57 @@ module Paperclip
assert_accepts
(
matcher
,
klass
)
end
end
# Stubs the HTTP PUT for an attachment using S3 storage.
#
# @example
# stub_paperclip_s3('user', 'avatar', 'png')
def
stub_paperclip_s3
(
model
,
attachment
,
extension
)
definition
=
model
.
gsub
(
" "
,
"_"
).
classify
.
constantize
.
attachment_definitions
[
attachment
.
to_sym
]
path
=
"http://s3.amazonaws.com/:id/
#{
definition
[
:path
]
}
"
path
.
gsub!
(
/:([^\/\.]+)/
)
do
|
match
|
"([^
\/\.
]+)"
end
begin
FakeWeb
.
register_uri
(
:put
,
Regexp
.
new
(
path
),
:body
=>
"OK"
)
rescue
NameError
raise
NameError
,
"the stub_paperclip_s3 shoulda macro requires the fakeweb gem."
end
end
# Stub S3 and return a file for attachment. Best with Factory Girl.
# Uses a strict directory convention:
#
# features/support/paperclip
#
# This method is used by the Paperclip-provided Cucumber step:
#
# When I attach a "demo_tape" "mp3" file to a "band" on S3
#
# @example
# Factory.define :band_with_demo_tape, :parent => :band do |band|
# band.demo_tape { band.paperclip_fixture("band", "demo_tape", "png") }
# end
def
paperclip_fixture
(
model
,
attachment
,
extension
)
stub_paperclip_s3
(
model
,
attachment
,
extension
)
base_path
=
File
.
join
(
File
.
dirname
(
__FILE__
),
".."
,
".."
,
"features"
,
"support"
,
"paperclip"
)
File
.
new
(
File
.
join
(
base_path
,
model
,
"
#{
attachment
}
.
#{
extension
}
"
))
end
end
end
class
ActionController
::
Integration
::
Session
#:nodoc:
include
Paperclip
::
Shoulda
end
class
Factory
include
Paperclip
::
Shoulda
#:nodoc:
end
class
Test
::
Unit
::
TestCase
#:nodoc:
extend
Paperclip
::
Shoulda
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment