paperclip_upload 0.1.0

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.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +36 -0
  4. data/app/assets/javascripts/paperclip_upload/application.js +13 -0
  5. data/app/assets/stylesheets/paperclip_upload/application.css +15 -0
  6. data/app/controllers/paperclip_upload/application_controller.rb +4 -0
  7. data/app/controllers/paperclip_upload/uploads_controller.rb +24 -0
  8. data/app/helpers/paperclip_upload/application_helper.rb +4 -0
  9. data/app/models/paperclip_upload/upload.rb +21 -0
  10. data/app/responders/paperclip_upload_responder.rb +41 -0
  11. data/app/serializers/paperclip_upload/upload_serializer.rb +3 -0
  12. data/app/views/layouts/paperclip_upload/application.html.erb +14 -0
  13. data/config/routes.rb +3 -0
  14. data/db/migrate/20150612152328_create_paperclip_upload_uploads.rb +7 -0
  15. data/db/migrate/20150612152417_add_attachment_file_to_uploads.rb +11 -0
  16. data/lib/generators/paperclip_upload/install_generator.rb +14 -0
  17. data/lib/paperclip_upload/active_record_extension.rb +41 -0
  18. data/lib/paperclip_upload/engine.rb +5 -0
  19. data/lib/paperclip_upload/version.rb +3 -0
  20. data/lib/paperclip_upload.rb +8 -0
  21. data/lib/tasks/paperclip_upload_tasks.rake +4 -0
  22. data/spec/dummy/README.rdoc +28 -0
  23. data/spec/dummy/Rakefile +6 -0
  24. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  25. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  26. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  27. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  28. data/spec/dummy/app/models/promotion.rb +19 -0
  29. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  30. data/spec/dummy/bin/bundle +3 -0
  31. data/spec/dummy/bin/rails +4 -0
  32. data/spec/dummy/bin/rake +4 -0
  33. data/spec/dummy/bin/setup +29 -0
  34. data/spec/dummy/config/application.rb +26 -0
  35. data/spec/dummy/config/boot.rb +5 -0
  36. data/spec/dummy/config/database.yml +25 -0
  37. data/spec/dummy/config/environment.rb +5 -0
  38. data/spec/dummy/config/environments/development.rb +41 -0
  39. data/spec/dummy/config/environments/production.rb +79 -0
  40. data/spec/dummy/config/environments/test.rb +42 -0
  41. data/spec/dummy/config/initializers/assets.rb +11 -0
  42. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  43. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  44. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  45. data/spec/dummy/config/initializers/inflections.rb +16 -0
  46. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  47. data/spec/dummy/config/initializers/session_store.rb +3 -0
  48. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  49. data/spec/dummy/config/locales/en.yml +23 -0
  50. data/spec/dummy/config/routes.rb +4 -0
  51. data/spec/dummy/config/secrets.yml +22 -0
  52. data/spec/dummy/config.ru +4 -0
  53. data/spec/dummy/db/development.sqlite3 +0 -0
  54. data/spec/dummy/db/migrate/20150612173816_create_paperclip_upload_uploads.paperclip_upload.rb +8 -0
  55. data/spec/dummy/db/migrate/20150612173817_add_attachment_file_to_uploads.paperclip_upload.rb +12 -0
  56. data/spec/dummy/db/migrate/20150613212501_create_promotions.rb +8 -0
  57. data/spec/dummy/db/migrate/20150613212609_add_attachment_photo_to_promotions.rb +11 -0
  58. data/spec/dummy/db/schema.rb +34 -0
  59. data/spec/dummy/db/test.sqlite3 +0 -0
  60. data/spec/dummy/log/RAILS_ENV=test.log +0 -0
  61. data/spec/dummy/log/development.log +5108 -0
  62. data/spec/dummy/log/test.log +12968 -0
  63. data/spec/dummy/public/404.html +67 -0
  64. data/spec/dummy/public/422.html +67 -0
  65. data/spec/dummy/public/500.html +66 -0
  66. data/spec/dummy/public/favicon.ico +0 -0
  67. data/spec/dummy/spec/assets/bukowski.jpg +0 -0
  68. data/spec/dummy/spec/controllers/paperclip_upload/uploads_controller_spec.rb +27 -0
  69. data/spec/dummy/spec/models/paperclip_upload/upload_spec.rb +14 -0
  70. data/spec/dummy/spec/models/promotion_spec.rb +83 -0
  71. data/spec/dummy/tmp/promotions/1/bukowski.jpg +0 -0
  72. data/spec/dummy/tmp/promotions/1/data +0 -0
  73. data/spec/dummy/tmp/uploads/1/bukowski.jpg +0 -0
  74. data/spec/dummy/tmp/uploads/2/Marilyn_Manson_imagen_003.jpg +0 -0
  75. data/spec/dummy/tmp/uploads/2/bukowski.jpg +0 -0
  76. data/spec/dummy/tmp/uploads/3/Marilyn_Manson_imagen_005.jpg +0 -0
  77. data/spec/dummy/tmp/uploads/3/bukowski.jpg +0 -0
  78. data/spec/dummy/tmp/uploads/4/Marilyn_Manson_imagen_005.jpg +0 -0
  79. data/spec/factories/paperclip_upload/uploads.rb +7 -0
  80. data/spec/factories/promotions.rb +13 -0
  81. data/spec/rails_helper.rb +26 -0
  82. data/spec/spec_helper.rb +87 -0
  83. data/spec/support/controller_helpers.rb +16 -0
  84. metadata +370 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
Binary file
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe PaperclipUpload::UploadsController, type: :controller do
4
+ routes { PaperclipUpload::Engine.routes }
5
+
6
+ describe "GET 'show'" do
7
+ let!(:upload) { create(:upload) }
8
+
9
+ it "returns 200 with existent id" do
10
+ get :show, id: upload.id, format: :json
11
+ expect(response).to be_success
12
+ expect(json_response.upload.id).to eq(upload.id)
13
+ end
14
+ end
15
+
16
+ describe "POST 'create'" do
17
+ context "sending file attachment" do
18
+ let(:file) { fixture_file_upload(Rails.root.join('spec', 'assets', 'bukowski.jpg')) }
19
+
20
+ it "returns 201" do
21
+ post :create, file: file, format: :json
22
+ expect(response).to be_success
23
+ expect(json_response.upload.id).not_to be_nil
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe PaperclipUpload::Upload, type: :model do
4
+ let(:upload) { build(:upload) }
5
+
6
+ it "has a valid factory" do
7
+ expect(upload).to be_valid
8
+ end
9
+
10
+ describe "validations" do
11
+ it { should have_attached_file(:file) }
12
+ it { should validate_attachment_presence(:file) }
13
+ end
14
+ end
@@ -0,0 +1,83 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Promotion, type: :model do
4
+ let(:promotion) { create(:promotion) }
5
+
6
+ describe "#has_attached_upload" do
7
+ it "has has_attached_upload method" do
8
+ expect(Promotion).to respond_to(:has_attached_upload)
9
+ end
10
+
11
+ it "wraps has_attached_file paperclip method" do
12
+ expect(Promotion.new.photo).to be_a(Paperclip::Attachment)
13
+ end
14
+
15
+ it "has upload accessors" do
16
+ promotion.upload = "upload"
17
+ expect(promotion.upload).to eq("upload")
18
+ end
19
+
20
+ it "has upload_id accessor" do
21
+ promotion.upload_id = "upload_id"
22
+ expect(promotion.upload_id).to eq("upload_id")
23
+ end
24
+
25
+ context "saving promotion" do
26
+ context "with invalid upload" do
27
+ it "raise error passing an invalid upload_id" do
28
+ promotion.upload_id = "invalid upload id"
29
+ expect { promotion.save }.to raise_error(ActiveRecord::RecordNotFound)
30
+ end
31
+
32
+ it "raise error passing an invalid upload" do
33
+ promotion.upload = "invalid upload"
34
+ expect { promotion.save }.to raise_error("invalid PaperclipUpload::Upload instance")
35
+ end
36
+ end
37
+
38
+ context "with valid upload" do
39
+ let(:upload) { create(:upload) }
40
+
41
+ def saves_with_upload
42
+ expect(promotion.photo.exists?).to be_falsy
43
+ yield(promotion)
44
+ expect(promotion.save).to be_truthy
45
+ expect(promotion.photo.exists?).to be_truthy
46
+ expect { PaperclipUpload::Upload.find(upload.id) }.to(
47
+ raise_error(ActiveRecord::RecordNotFound))
48
+ end
49
+
50
+ it "saves photo using upload instance" do
51
+ saves_with_upload { |promo| promotion.upload = upload }
52
+ end
53
+
54
+ it "saves photo using upload_id" do
55
+ saves_with_upload { |promo| promotion.upload_id = upload.id }
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "#allow_encoded_file_for" do
62
+ it "has allow_encoded_file_for method" do
63
+ expect(Promotion).to respond_to(:allow_encoded_file_for)
64
+ end
65
+
66
+ it "has encoded_photo accessor" do
67
+ promotion.encoded_photo = "encoded_photo"
68
+ expect(promotion.encoded_photo).to eq("encoded_photo")
69
+ end
70
+
71
+ context "saving promotion" do
72
+ context "with encoded photo" do
73
+ let(:encoded_promotion) { build(:promotion_with_encoded_photo) }
74
+
75
+ it "decodes and save photo" do
76
+ expect(encoded_promotion.photo.exists?).to be_falsy
77
+ expect(encoded_promotion.save).to be_truthy
78
+ expect(encoded_promotion.photo.exists?).to be_truthy
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
Binary file
@@ -0,0 +1,7 @@
1
+ include ActionDispatch::TestProcess
2
+
3
+ FactoryGirl.define do
4
+ factory :upload, :class => 'PaperclipUpload::Upload' do
5
+ file { fixture_file_upload(Rails.root.join('spec', 'assets', 'bukowski.jpg'), 'image/png') }
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ FactoryGirl.define do
2
+ factory :promotion do
3
+ photo nil
4
+
5
+ factory :promotion_with_photo do
6
+ photo { fixture_file_upload(Rails.root.join('spec', 'assets', 'bukowski.jpg')) }
7
+ end
8
+
9
+ factory :promotion_with_encoded_photo do
10
+ encoded_photo { Base64.encode64(File.open(Rails.root.join('spec', 'assets', 'bukowski.jpg')).read) }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'spec_helper'
6
+ require 'factory_girl_rails'
7
+ require 'shoulda-matchers'
8
+ require 'paperclip/matchers'
9
+ require 'recursive_open_struct'
10
+
11
+ ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
12
+ Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
13
+
14
+ ActiveRecord::Migration.maintain_test_schema!
15
+
16
+ RSpec.configure do |config|
17
+ config.use_transactional_fixtures = true
18
+ config.infer_spec_type_from_file_location!
19
+ config.order = :random
20
+ config.render_views
21
+ config.include FactoryGirl::Syntax::Methods
22
+ config.include Paperclip::Shoulda::Matchers
23
+ config.include ControllerHelpers, type: :controller
24
+
25
+ FactoryGirl::SyntaxRunner.send(:include, RSpec::Mocks::ExampleMethods)
26
+ end
@@ -0,0 +1,87 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # Many RSpec users commonly either run the entire suite or an individual
61
+ # file, and it's useful to allow more verbose output when running an
62
+ # individual spec file.
63
+ if config.files_to_run.one?
64
+ # Use the documentation formatter for detailed output,
65
+ # unless a formatter has already been configured
66
+ # (e.g. via a command-line flag).
67
+ config.default_formatter = 'doc'
68
+ end
69
+
70
+ # Print the 10 slowest examples and example groups at the
71
+ # end of the spec run, to help surface which specs are running
72
+ # particularly slow.
73
+ config.profile_examples = 10
74
+
75
+ # Run specs in random order to surface order dependencies. If you find an
76
+ # order dependency and want to debug it, you can fix the order by providing
77
+ # the seed, which is printed after each run.
78
+ # --seed 1234
79
+ config.order = :random
80
+
81
+ # Seed global randomization in this process using the `--seed` CLI option.
82
+ # Setting this allows you to use `--seed` to deterministically reproduce
83
+ # test failures related to randomization by passing the same `--seed` value
84
+ # as the one that triggered the failure.
85
+ Kernel.srand config.seed
86
+ =end
87
+ end
@@ -0,0 +1,16 @@
1
+ module ControllerHelpers
2
+ def json_response
3
+ @json_response ||= ControllerHelpers.calculate_json_response(JSON.parse(response.body))
4
+ end
5
+
6
+ def self.calculate_json_response(item)
7
+ case item
8
+ when Array
9
+ item.map! { |i| calculate_json_response(i) }
10
+ when Hash
11
+ RecursiveOpenStruct.new(item)
12
+ else
13
+ item
14
+ end
15
+ end
16
+ end