transloadit-rails 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -206,3 +206,37 @@ $ rails server
206
206
  Then go to http://localhost:3000/uploads/new, and upload an image. If you did
207
207
  everything right, you should see the uploaded and resized file as soon as the
208
208
  upload finishes.
209
+
210
+ ## Testing
211
+
212
+ ### RSpec request specs
213
+
214
+ If you want to test your file uploads without relying on the network (a
215
+ good idea to keep them fast and lean) you can include some request spec
216
+ helpers to allow you to easily populate the `transloadit_params` and
217
+ `params[:transloadit]` in your actions.
218
+
219
+ First, in your `spec/spec_helper.rb` :
220
+ ```ruby
221
+ require 'transloadit/rspec/helpers'
222
+ ```
223
+
224
+ Now, in your request spec :
225
+ ```ruby
226
+ # NOTE: It's important that you don't use :js => true, otherwise your
227
+ # test will actually hit out using AJAX, making your test dependent on the
228
+ # network.
229
+ it "can upload data files", :js => false do
230
+ attach_file 'upload_file', Rails.root.join('spec', 'asset', 'example.pdf')
231
+
232
+ # UploadsController should be replaced with the actual controller
233
+ # you're expecting to POST to when the upload is done
234
+ stub_transloadit!(UploadsController, example_json)
235
+
236
+ click_button 'Submit'
237
+ end
238
+
239
+ def example_json
240
+ "{ ... JSON content from a real POST ... }"
241
+ end
242
+ ```
@@ -8,10 +8,20 @@ module Transloadit::Rails::ParamsDecoder
8
8
  end
9
9
 
10
10
  def decode_transloadit_json
11
- return unless params[:transloadit].present?
11
+ params[:transloadit] = transloadit_params
12
+ end
13
+
14
+ # Returns true if the current request has transloadit data.
15
+ def transloadit?
16
+ params[:transloadit].present?
17
+ end
18
+
19
+ # Returns the decoded transloadit parameters, or nil if the current request does not contain them.
20
+ def transloadit_params
21
+ return unless transloadit?
12
22
 
13
23
  # wrap transloadit params in a HashWithIndifferentAccess
14
- params[:transloadit] = ActiveSupport::HashWithIndifferentAccess.new(
24
+ ActiveSupport::HashWithIndifferentAccess.new(
15
25
  ActiveSupport::JSON.decode params[:transloadit]
16
26
  )
17
27
  end
@@ -1,5 +1,5 @@
1
1
  class Transloadit
2
2
  module Rails
3
- VERSION = '1.0.6'
3
+ VERSION = '1.0.7'
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ if defined?(RSpec) then
2
+ require 'transloadit/rspec/request_spec_helper'
3
+ else
4
+ raise "RSpec doesn't appear to be loaded!"
5
+ end
@@ -0,0 +1,28 @@
1
+ class Transloadit
2
+ module RSpec
3
+ # Provides helper methods to help stub a request to Transloadit in a non-JS request spec.
4
+ module RequestSpecHelper
5
+ # Stubs the relevant calls to the controller so as that a request spec can
6
+ # test Transloadit parameters without needing to actually make a call to the
7
+ # server.
8
+ #
9
+ # +controller+ should be the class of the controller you are about to invoke.
10
+ # +params_json+ should be the JSON content as returned by Transloadit.
11
+ #
12
+ # It's usually easiest to make the request with your development environment,
13
+ # capture the JSON response from the logs and use that in your tests.
14
+ def stub_transloadit!(controller, params_json)
15
+ hash = ActiveSupport::HashWithIndifferentAccess.new(
16
+ ActiveSupport::JSON.decode params_json
17
+ )
18
+
19
+ controller.any_instance.stub(:transloadit?).and_return(true)
20
+ controller.any_instance.stub(:transloadit_params).and_return(hash)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ RSpec.configure do |config|
27
+ config.include Transloadit::RSpec::RequestSpecHelper, :type => :request
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transloadit-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-13 00:00:00.000000000 Z
13
+ date: 2012-07-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: transloadit
17
- requirement: &70231801790380 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: 1.0.2
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70231801790380
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 1.0.2
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: railties
28
- requirement: &70231801783700 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ~>
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '3'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70231801783700
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '3'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rake
39
- requirement: &70231801783200 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '0'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70231801783200
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: minitest
50
- requirement: &70231801782460 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '0'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70231801782460
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: simplecov
61
- requirement: &70231801781100 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ! '>='
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: '0'
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *70231801781100
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: yard
72
- requirement: &70231801779980 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ! '>='
@@ -77,10 +102,15 @@ dependencies:
77
102
  version: '0'
78
103
  type: :development
79
104
  prerelease: false
80
- version_requirements: *70231801779980
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
81
111
  - !ruby/object:Gem::Dependency
82
112
  name: rdiscount
83
- requirement: &70231801777100 !ruby/object:Gem::Requirement
113
+ requirement: !ruby/object:Gem::Requirement
84
114
  none: false
85
115
  requirements:
86
116
  - - ! '>='
@@ -88,7 +118,12 @@ dependencies:
88
118
  version: '0'
89
119
  type: :development
90
120
  prerelease: false
91
- version_requirements: *70231801777100
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
92
127
  description: The transloadit-rails gem allows you to automate uploading files through
93
128
  the Transloadit REST API
94
129
  email:
@@ -112,6 +147,8 @@ files:
112
147
  - lib/transloadit/rails/params_decoder.rb
113
148
  - lib/transloadit/rails/version.rb
114
149
  - lib/transloadit/rails/view_helper.rb
150
+ - lib/transloadit/rspec/helpers.rb
151
+ - lib/transloadit/rspec/request_spec_helper.rb
115
152
  - test/generators/transloadit/test_install_generator.rb
116
153
  - test/test_helper.rb
117
154
  - transloadit-rails.gemspec
@@ -135,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
172
  version: 1.3.6
136
173
  requirements: []
137
174
  rubyforge_project: transloadit-rails
138
- rubygems_version: 1.8.11
175
+ rubygems_version: 1.8.23
139
176
  signing_key:
140
177
  specification_version: 3
141
178
  summary: Official Rails gem for Transloadit