attachy 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +3 -0
  4. data/lib/assets/javascripts/attachy.js +1 -1
  5. data/lib/attachy.rb +3 -1
  6. data/lib/attachy/builders/attachy/form_builder.rb +2 -0
  7. data/lib/attachy/engine.rb +2 -0
  8. data/lib/attachy/helpers/attachy/view_helper.rb +2 -0
  9. data/lib/attachy/models/attachy/extension.rb +2 -0
  10. data/lib/attachy/models/attachy/file.rb +2 -0
  11. data/lib/attachy/models/attachy/viewer.rb +2 -0
  12. data/lib/attachy/version.rb +3 -1
  13. data/lib/generators/attachy/install_generator.rb +2 -0
  14. data/lib/generators/attachy/templates/db/migrate/create_attachy_files_table.rb +3 -1
  15. data/spec/builders/attachy/form_builder/attachy_content_spec.rb +2 -0
  16. data/spec/builders/attachy/form_builder/attachy_file_field_spec.rb +2 -0
  17. data/spec/builders/attachy/form_builder/attachy_spec.rb +2 -0
  18. data/spec/factories/attachy/file.rb +2 -0
  19. data/spec/factories/user.rb +2 -0
  20. data/spec/helpers/attachy/attachy_content_spec.rb +2 -0
  21. data/spec/helpers/attachy/attachy_file_field_spec.rb +2 -0
  22. data/spec/helpers/attachy/attachy_spec.rb +2 -0
  23. data/spec/models/attachy/callback/destroy_file_spec.rb +2 -0
  24. data/spec/models/attachy/callback/remove_tmp_tag_spec.rb +2 -0
  25. data/spec/models/attachy/extension/user/avatar_spec.rb +5 -4
  26. data/spec/models/attachy/extension/user/photos_spec.rb +5 -4
  27. data/spec/models/attachy/file/config_spec.rb +2 -0
  28. data/spec/models/attachy/file/default_spec.rb +2 -0
  29. data/spec/models/attachy/file/path_spec.rb +2 -0
  30. data/spec/models/attachy/file/transform_spec.rb +2 -0
  31. data/spec/models/attachy/file_spec.rb +2 -0
  32. data/spec/models/attachy/viewer/attachments_spec.rb +4 -2
  33. data/spec/models/attachy/viewer/button_label_options_spec.rb +4 -2
  34. data/spec/models/attachy/viewer/button_label_spec.rb +4 -2
  35. data/spec/models/attachy/viewer/content_options_spec.rb +4 -2
  36. data/spec/models/attachy/viewer/content_spec.rb +4 -2
  37. data/spec/models/attachy/viewer/field_options_spec.rb +4 -2
  38. data/spec/models/attachy/viewer/field_spec.rb +4 -2
  39. data/spec/models/attachy/viewer/file_button_options_spec.rb +4 -2
  40. data/spec/models/attachy/viewer/file_button_spec.rb +4 -2
  41. data/spec/models/attachy/viewer/file_field_options_spec.rb +6 -4
  42. data/spec/models/attachy/viewer/file_field_spec.rb +4 -2
  43. data/spec/models/attachy/viewer/hidden_field_spec.rb +4 -2
  44. data/spec/models/attachy/viewer/image_spec.rb +4 -2
  45. data/spec/models/attachy/viewer/link_options_spec.rb +4 -2
  46. data/spec/models/attachy/viewer/link_spec.rb +4 -2
  47. data/spec/models/attachy/viewer/node_options_spec.rb +4 -2
  48. data/spec/models/attachy/viewer/node_spec.rb +2 -0
  49. data/spec/models/attachy/viewer/nodes_spec.rb +5 -3
  50. data/spec/models/attachy/viewer/remove_button_options_spec.rb +4 -2
  51. data/spec/models/attachy/viewer/transform_spec.rb +4 -2
  52. data/spec/models/attachy/viewer/value_spec.rb +8 -6
  53. data/spec/models/user_spec.rb +2 -0
  54. data/spec/support/common.rb +2 -0
  55. data/spec/support/database_cleaner.rb +2 -0
  56. data/spec/support/db/migrate/create_users_table.rb +2 -0
  57. data/spec/support/factory_girl.rb +2 -0
  58. data/spec/support/html_matchers.rb +2 -0
  59. data/spec/support/migrate.rb +2 -0
  60. data/spec/support/models/user.rb +2 -0
  61. data/spec/support/shoulda.rb +2 -0
  62. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a029ab515bf4b323047c5231ecfe7e30d90e552e
4
- data.tar.gz: f1454ca82ee9055a1214562d743d9ff0db114e9f
3
+ metadata.gz: ac80ed2f422a74828c71af232340b5e37f091eb9
4
+ data.tar.gz: 70fca26a7ae273e3c91c2424b103984e88d00c3c
5
5
  SHA512:
6
- metadata.gz: b349429b795c329775229fe57f2ade6f7dd12b49458a63354c688b74aeb1fe5b1b6e3aacf34acad947d6082b8fee611d579b7e412f3049dc4acee66dea146c81
7
- data.tar.gz: 47f608b456d919a95b0bbb555788c972ef86d861b7f3c0abcc10b8267771cd031372c1782b54fc4c4fb7a4639621bbecd2b72195527fd232cfed927f1b8feec0
6
+ metadata.gz: 7f9159e3b620f5a67810d3d81ee76c5a9dd55cb2b8a51f2e427bfcd78383a46c17f97bd31a975e68245a580ce5b60edc551368d51c79f016ce047b179a44d9e3
7
+ data.tar.gz: 8d1d41a614f9e7bb6be422fd70cc0787a96255bf357173cd39c6eb9213cb4b2cb3f8c759e0a91271e6d4c828234c2585e0864e1715920bfd2590a13df0a63a19
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.2.0
2
+
3
+ - Bump Rails to 5.x;
4
+ - Bump Ruby to 2.4.1.
5
+
1
6
  # 0.1.2
2
7
 
3
8
  - Added `ruby-version`;
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Attachy
2
2
 
3
+ [![Build Status](https://travis-ci.org/wbotelhos/attachy.svg)](https://travis-ci.org/wbotelhos/attachy)
4
+ [![Gem Version](https://badge.fury.io/rb/attachy.svg)](https://badge.fury.io/rb/attachy)
5
+
3
6
  Attachments handler for Rails via http://cloudinary.com
4
7
 
5
8
  ## Description
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @author : Washington Botelho
7
7
  * @doc : http://wbotelhos.com/attachy
8
- * @version : 0.1.2
8
+ * @version : 0.2.0
9
9
  *
10
10
  */
11
11
 
data/lib/attachy.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Attachy
2
- ENV_TAG = "attachy_#{Rails.env}".freeze
4
+ ENV_TAG = "attachy_#{Rails.env}"
3
5
  TMP_TAG = :attachy_tmp
4
6
  end
5
7
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Attachy
2
4
  module FormBuilder
3
5
  def attachy(method, options = {}, &block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'attachy/builders/attachy/form_builder'
2
4
  require 'attachy/helpers/attachy/view_helper'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Attachy
2
4
  module ViewHelper
3
5
  def attachy(method, object, options, block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Attachy
2
4
  module Extension
3
5
  extend ActiveSupport::Concern
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Attachy
2
4
  class File < ::ActiveRecord::Base
3
5
  self.table_name = 'attachy_files'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mime/types'
2
4
 
3
5
  module Attachy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Attachy
2
- VERSION = '0.1.2'.freeze
4
+ VERSION = '0.2.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Attachy
2
4
  class InstallGenerator < Rails::Generators::Base
3
5
  source_root File.expand_path('../templates', __FILE__)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateAttachyFilesTable < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  create_table :attachy_files do |t|
@@ -14,6 +16,6 @@ class CreateAttachyFilesTable < ActiveRecord::Migration[5.0]
14
16
  t.timestamps null: false
15
17
  end
16
18
 
17
- add_index :attachy_files, [:attachable_type, :attachable_id, :scope], name: :index_attachy_files_on_attachable_and_scope
19
+ add_index :attachy_files, %i[attachable_type attachable_id scope], name: :index_attachy_files_on_attachable_and_scope
18
20
  end
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  class Dummy < ActionView::Helpers::FormBuilder
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  class Dummy < ActionView::Helpers::FormBuilder
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  class Dummy < ActionView::Helpers::FormBuilder
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryGirl.define do
2
4
  factory :file, class: Attachy::File do
3
5
  format :jpg
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryGirl.define do
2
4
  factory :user do
3
5
  sequence(:name) { |i| "Name #{i}" }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  class DummyHelper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  class DummyHelper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  class DummyHelper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe User, ':destroy_file' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe User, ':remove_tmp_tag' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe User, ':avatar' do
@@ -79,7 +81,7 @@ RSpec.describe User, ':avatar' do
79
81
  it 'does not creates a new one' do
80
82
  user.avatar = json
81
83
 
82
- expect { user.avatar_files }.to_not change(Attachy::File, :count)
84
+ expect { user.avatar_files }.not_to change(Attachy::File, :count)
83
85
  end
84
86
 
85
87
  it 'is referenced' do
@@ -95,7 +97,7 @@ RSpec.describe User, ':avatar' do
95
97
  it 'does not creates a new one' do
96
98
  user.avatar = json
97
99
 
98
- expect { user.avatar_files }.to_not change(Attachy::File, :count)
100
+ expect { user.avatar_files }.not_to change(Attachy::File, :count)
99
101
  end
100
102
 
101
103
  it 'is referenced' do
@@ -113,8 +115,7 @@ RSpec.describe User, ':avatar' do
113
115
  height: 600,
114
116
  public_id: :public_id,
115
117
  scope: :avatar,
116
- width: 800
117
- )
118
+ width: 800)
118
119
  end
119
120
 
120
121
  context 'as a json' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe User, ':photos' do
@@ -75,7 +77,7 @@ RSpec.describe User, ':photos' do
75
77
  it 'does not creates a new one' do
76
78
  user.photos = json
77
79
 
78
- expect { user.photos_files }.to_not change(Attachy::File, :count)
80
+ expect { user.photos_files }.not_to change(Attachy::File, :count)
79
81
  end
80
82
 
81
83
  it 'is referenced' do
@@ -91,7 +93,7 @@ RSpec.describe User, ':photos' do
91
93
  it 'does not creates a new one' do
92
94
  user.photos = json
93
95
 
94
- expect { user.photos_files }.to_not change(Attachy::File, :count)
96
+ expect { user.photos_files }.not_to change(Attachy::File, :count)
95
97
  end
96
98
 
97
99
  it 'is referenced' do
@@ -109,8 +111,7 @@ RSpec.describe User, ':photos' do
109
111
  height: 600,
110
112
  public_id: :public_id,
111
113
  scope: :photo,
112
- width: 800
113
- )
114
+ width: 800)
114
115
  end
115
116
 
116
117
  context 'as a json' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::File, '#config' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::File, '#default' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::File, '.url' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::File, '.transform' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::File do
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.attachments' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
 
6
10
  before { allow(Cloudinary::Uploader).to receive(:remove_tag) }
7
11
 
8
- subject { described_class.new method, object }
9
-
10
12
  context 'with one file' do
11
13
  let!(:method) { :avatar }
12
14
  let!(:file) { create :file, attachable: object, scope: method }
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.button_label_options' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
  let(:file) { create :file, attachable: object, scope: method }
7
11
 
8
12
  before { allow(Cloudinary::Uploader).to receive(:remove_tag) }
9
13
 
10
- subject { described_class.new method, object }
11
-
12
14
  it 'returns the default button label options' do
13
15
  expect(subject.button_label_options).to eq(text: '...')
14
16
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.button_label' do
6
+ subject { described_class.new method, object, options }
7
+
4
8
  let!(:method) { :avatar }
5
9
  let!(:object) { create :user }
6
10
  let(:file) { create :file, attachable: object }
@@ -8,8 +12,6 @@ RSpec.describe Attachy::Viewer, '.button_label' do
8
12
 
9
13
  before { allow(Cloudinary::Uploader).to receive(:remove_tag) }
10
14
 
11
- subject { described_class.new method, object, options }
12
-
13
15
  describe 'default options' do
14
16
  it 'uses generic button options' do
15
17
  el = subject.button_label
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.content_options' do
6
+ subject { described_class.new method, object, options }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
  let(:file) { create :file, attachable: object, scope: method }
@@ -12,8 +16,6 @@ RSpec.describe Attachy::Viewer, '.content_options' do
12
16
  allow(subject).to receive(:metadata) { { crop: :crop, multiple: :multiple } }
13
17
  end
14
18
 
15
- subject { described_class.new method, object, options }
16
-
17
19
  it 'returns the default field options' do
18
20
  expect(subject.content_options).to eq(
19
21
  class: :attachy__content,
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.content' do
6
+ subject { described_class.new method, object, options }
7
+
4
8
  let!(:method) { :avatar }
5
9
  let!(:object) { create :user }
6
10
  let!(:options) { { button: { html: { key: :value } } } }
@@ -22,8 +26,6 @@ RSpec.describe Attachy::Viewer, '.content' do
22
26
  allow(subject).to receive(:content_options) { { class: :attachy__content } }
23
27
  end
24
28
 
25
- subject { described_class.new method, object, options }
26
-
27
29
  describe 'default options' do
28
30
  it 'uses generic button options' do
29
31
  el = subject.content
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.field_options' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
 
@@ -10,8 +14,6 @@ RSpec.describe Attachy::Viewer, '.field_options' do
10
14
  create :file, attachable: object, scope: method
11
15
  end
12
16
 
13
- subject { described_class.new method, object }
14
-
15
17
  it 'returns the default field options' do
16
18
  expect(subject.field_options).to eq(class: :attachy)
17
19
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.field' do
6
+ subject { described_class.new method, object, options }
7
+
4
8
  let!(:method) { :avatar }
5
9
  let!(:object) { create :user }
6
10
  let!(:options) { { button: { html: { key: :value } } } }
@@ -16,8 +20,6 @@ RSpec.describe Attachy::Viewer, '.field' do
16
20
  allow(subject).to receive(:file_button) { '2' }
17
21
  end
18
22
 
19
- subject { described_class.new method, object, options }
20
-
21
23
  describe 'default options' do
22
24
  it 'uses generic button options' do
23
25
  el = subject.field
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.file_button_options' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
 
@@ -10,8 +14,6 @@ RSpec.describe Attachy::Viewer, '.file_button_options' do
10
14
  create :file, attachable: object, scope: method
11
15
  end
12
16
 
13
- subject { described_class.new method, object }
14
-
15
17
  it 'returns the default file button options' do
16
18
  expect(subject.file_button_options).to eq(class: :attachy__button)
17
19
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.file_button' do
6
+ subject { described_class.new method, object, options }
7
+
4
8
  let!(:method) { :avatar }
5
9
  let!(:object) { create :user }
6
10
  let!(:options) { { button: { html: { key: :value } } } }
@@ -11,8 +15,6 @@ RSpec.describe Attachy::Viewer, '.file_button' do
11
15
  create :file, attachable: object
12
16
  end
13
17
 
14
- subject { described_class.new method, object, options }
15
-
16
18
  before do
17
19
  allow(subject).to receive(:button_label) { '1' }
18
20
  allow(subject).to receive(:file_field) { '2' }
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.file_field_options' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
 
@@ -10,8 +14,6 @@ RSpec.describe Attachy::Viewer, '.file_field_options' do
10
14
  create :file, attachable: object, scope: method
11
15
  end
12
16
 
13
- subject { described_class.new method, object }
14
-
15
17
  context 'when :accept has invalid mime type' do
16
18
  context 'with one type' do
17
19
  before do
@@ -27,7 +29,7 @@ RSpec.describe Attachy::Viewer, '.file_field_options' do
27
29
 
28
30
  context 'with more than one type' do
29
31
  before do
30
- allow(subject).to receive(:metadata) { { accept: [:abc, :png] } }
32
+ allow(subject).to receive(:metadata) { { accept: %i[abc png] } }
31
33
  end
32
34
 
33
35
  it 'is added as attribute only the valid one' do
@@ -53,7 +55,7 @@ RSpec.describe Attachy::Viewer, '.file_field_options' do
53
55
 
54
56
  context 'with more than one type' do
55
57
  before do
56
- allow(subject).to receive(:metadata) { { accept: [:jpg, :png] } }
58
+ allow(subject).to receive(:metadata) { { accept: %i[jpg png] } }
57
59
  end
58
60
 
59
61
  it 'is added as attribute' do
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
  require 'cloudinary'
3
5
 
4
6
  RSpec.describe Attachy::Viewer, '.file_field' do
7
+ subject { described_class.new method, object, options, view }
8
+
5
9
  let!(:method) { :avatar }
6
10
  let!(:object) { create :user }
7
11
  let!(:options) { {} }
@@ -15,8 +19,6 @@ RSpec.describe Attachy::Viewer, '.file_field' do
15
19
 
16
20
  before { allow(subject).to receive(:file_field_options) { { key: :value } } }
17
21
 
18
- subject { described_class.new method, object, options, view }
19
-
20
22
  it 'returns the hidden field with attachments value' do
21
23
  allow(view).to receive(:cl_image_upload_tag).with(method, html: subject.file_field_options, tags: [Attachy::ENV_TAG, Attachy::TMP_TAG]) { :input }
22
24
 
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.hidden_field' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
 
@@ -12,8 +16,6 @@ RSpec.describe Attachy::Viewer, '.hidden_field' do
12
16
 
13
17
  before { allow(subject).to receive(:value) { :value } }
14
18
 
15
- subject { described_class.new method, object }
16
-
17
19
  it 'returns the hidden field with attachments value' do
18
20
  el = subject.hidden_field
19
21
 
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.image' do
6
+ subject { described_class.new method, object, options }
7
+
4
8
  let!(:method) { :avatar }
5
9
  let!(:object) { create :user }
6
10
  let!(:default_html) { { alt: :image, height: 50, width: 150 } }
@@ -13,8 +17,6 @@ RSpec.describe Attachy::Viewer, '.image' do
13
17
  create :file, attachable: object
14
18
  end
15
19
 
16
- subject { described_class.new method, object, options }
17
-
18
20
  context 'when :html is present' do
19
21
  let!(:html_attributes) { { alt: :alt, invalid: :invalid, height: 11, width: 22 } }
20
22
 
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.link_options' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
 
@@ -10,8 +14,6 @@ RSpec.describe Attachy::Viewer, '.link_options' do
10
14
  create :file, attachable: object, scope: method
11
15
  end
12
16
 
13
- subject { described_class.new method, object }
14
-
15
17
  it 'returns the default link options' do
16
18
  expect(subject.link_options).to eq(class: :attachy__link)
17
19
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.link' do
6
+ subject { described_class.new method, object, options }
7
+
4
8
  let!(:method) { :avatar }
5
9
  let!(:object) { create :user }
6
10
  let!(:default_html) { { alt: :image, height: 50, width: 150 } }
@@ -13,8 +17,6 @@ RSpec.describe Attachy::Viewer, '.link' do
13
17
  create :file, attachable: object
14
18
  end
15
19
 
16
- subject { described_class.new method, object, options }
17
-
18
20
  describe 'default options' do
19
21
  before do
20
22
  allow_any_instance_of(Attachy::File).to receive(:url).with(crop: :none) { 'http://example.org' }
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.node_options' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
 
@@ -10,8 +14,6 @@ RSpec.describe Attachy::Viewer, '.node_options' do
10
14
  create :file, attachable: object, scope: method
11
15
  end
12
16
 
13
- subject { described_class.new method, object }
14
-
15
17
  it 'returns the default node options' do
16
18
  expect(subject.node_options).to eq(class: :attachy__node)
17
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.node' do
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.nodes' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :photos }
6
10
  let(:file_1) { create :file, attachable: object, scope: method }
@@ -13,9 +17,7 @@ RSpec.describe Attachy::Viewer, '.nodes' do
13
17
  allow(subject).to receive(:node).with(file_2) { :node_2 }
14
18
  end
15
19
 
16
- subject { described_class.new method, object }
17
-
18
20
  it 'returns the nodes with links inside as an array' do
19
- expect(subject.nodes).to eq [:node_1, :node_2]
21
+ expect(subject.nodes).to eq %i[node_1 node_2]
20
22
  end
21
23
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.remove_button_options' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
 
@@ -10,8 +14,6 @@ RSpec.describe Attachy::Viewer, '.remove_button_options' do
10
14
  create :file, attachable: object, scope: method
11
15
  end
12
16
 
13
- subject { described_class.new method, object }
14
-
15
17
  it 'returns the default remove button options' do
16
18
  expect(subject.remove_button_options).to eq(class: :attachy__remove)
17
19
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.remove_button' do
6
+ subject { described_class.new method, object }
7
+
4
8
  let!(:object) { create :user }
5
9
  let!(:method) { :avatar }
6
10
 
@@ -10,8 +14,6 @@ RSpec.describe Attachy::Viewer, '.remove_button' do
10
14
  create :file, attachable: object, scope: method
11
15
  end
12
16
 
13
- subject { described_class.new method, object }
14
-
15
17
  context 'when give no html options' do
16
18
  it 'returns just the default options' do
17
19
  el = subject.remove_button
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe Attachy::Viewer, '.value' do
@@ -7,11 +9,11 @@ RSpec.describe Attachy::Viewer, '.value' do
7
9
 
8
10
  context 'when has one result' do
9
11
  context 'as attachament' do
12
+ subject { described_class.new method, object }
13
+
10
14
  let!(:method) { :avatar }
11
15
  let!(:file) { create :file, attachable: object, scope: method }
12
16
 
13
- subject { described_class.new method, object }
14
-
15
17
  context 'and it is not default' do
16
18
  let!(:default) { Attachy::File.new public_id: 0 }
17
19
 
@@ -38,11 +40,11 @@ RSpec.describe Attachy::Viewer, '.value' do
38
40
  end
39
41
 
40
42
  context 'as attachaments' do
43
+ subject { described_class.new method, object }
44
+
41
45
  let!(:method) { :photos }
42
46
  let!(:file) { create :file, attachable: object, scope: method }
43
47
 
44
- subject { described_class.new method, object }
45
-
46
48
  context 'and it is not default' do
47
49
  let!(:default) { Attachy::File.new public_id: 0 }
48
50
 
@@ -70,12 +72,12 @@ RSpec.describe Attachy::Viewer, '.value' do
70
72
  end
71
73
 
72
74
  context 'when has more than one result' do
75
+ subject { described_class.new method, object }
76
+
73
77
  let!(:method) { :photos }
74
78
  let!(:file_1) { create :file, attachable: object, scope: :photos }
75
79
  let!(:file_2) { create :file, attachable: object, scope: :photos }
76
80
 
77
- subject { described_class.new method, object }
78
-
79
81
  it 'is represented as json' do
80
82
  expect(subject.value).to eq [file_1, file_2].to_json
81
83
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe User do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec/rails'
2
4
 
3
5
  RSpec.configure do |config|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'database_cleaner'
2
4
 
3
5
  RSpec.configure do |config|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateUsersTable < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  create_table :users do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'factory_girl'
2
4
 
3
5
  Dir[File.expand_path('../factories/**/*.rb', __dir__)].each { |file| require file }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec-html-matchers'
2
4
 
3
5
  RSpec.configure do |config|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path('../../lib/generators/attachy/templates/db/migrate/create_attachy_files_table.rb', __dir__)
2
4
 
3
5
  CreateAttachyFilesTable.new.change
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class User < ::ActiveRecord::Base
2
4
  has_attachment :avatar, accept: %i[jpg png]
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'shoulda-matchers'
2
4
 
3
5
  Shoulda::Matchers.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attachy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-21 00:00:00.000000000 Z
11
+ date: 2017-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cloudinary
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -310,7 +310,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
310
310
  version: '0'
311
311
  requirements: []
312
312
  rubyforge_project:
313
- rubygems_version: 2.6.8
313
+ rubygems_version: 2.6.11
314
314
  signing_key:
315
315
  specification_version: 4
316
316
  summary: Attachments handler for Rails via Cloudinary.