attachy 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +3 -0
- data/lib/assets/javascripts/attachy.js +1 -1
- data/lib/attachy.rb +3 -1
- data/lib/attachy/builders/attachy/form_builder.rb +2 -0
- data/lib/attachy/engine.rb +2 -0
- data/lib/attachy/helpers/attachy/view_helper.rb +2 -0
- data/lib/attachy/models/attachy/extension.rb +2 -0
- data/lib/attachy/models/attachy/file.rb +2 -0
- data/lib/attachy/models/attachy/viewer.rb +2 -0
- data/lib/attachy/version.rb +3 -1
- data/lib/generators/attachy/install_generator.rb +2 -0
- data/lib/generators/attachy/templates/db/migrate/create_attachy_files_table.rb +3 -1
- data/spec/builders/attachy/form_builder/attachy_content_spec.rb +2 -0
- data/spec/builders/attachy/form_builder/attachy_file_field_spec.rb +2 -0
- data/spec/builders/attachy/form_builder/attachy_spec.rb +2 -0
- data/spec/factories/attachy/file.rb +2 -0
- data/spec/factories/user.rb +2 -0
- data/spec/helpers/attachy/attachy_content_spec.rb +2 -0
- data/spec/helpers/attachy/attachy_file_field_spec.rb +2 -0
- data/spec/helpers/attachy/attachy_spec.rb +2 -0
- data/spec/models/attachy/callback/destroy_file_spec.rb +2 -0
- data/spec/models/attachy/callback/remove_tmp_tag_spec.rb +2 -0
- data/spec/models/attachy/extension/user/avatar_spec.rb +5 -4
- data/spec/models/attachy/extension/user/photos_spec.rb +5 -4
- data/spec/models/attachy/file/config_spec.rb +2 -0
- data/spec/models/attachy/file/default_spec.rb +2 -0
- data/spec/models/attachy/file/path_spec.rb +2 -0
- data/spec/models/attachy/file/transform_spec.rb +2 -0
- data/spec/models/attachy/file_spec.rb +2 -0
- data/spec/models/attachy/viewer/attachments_spec.rb +4 -2
- data/spec/models/attachy/viewer/button_label_options_spec.rb +4 -2
- data/spec/models/attachy/viewer/button_label_spec.rb +4 -2
- data/spec/models/attachy/viewer/content_options_spec.rb +4 -2
- data/spec/models/attachy/viewer/content_spec.rb +4 -2
- data/spec/models/attachy/viewer/field_options_spec.rb +4 -2
- data/spec/models/attachy/viewer/field_spec.rb +4 -2
- data/spec/models/attachy/viewer/file_button_options_spec.rb +4 -2
- data/spec/models/attachy/viewer/file_button_spec.rb +4 -2
- data/spec/models/attachy/viewer/file_field_options_spec.rb +6 -4
- data/spec/models/attachy/viewer/file_field_spec.rb +4 -2
- data/spec/models/attachy/viewer/hidden_field_spec.rb +4 -2
- data/spec/models/attachy/viewer/image_spec.rb +4 -2
- data/spec/models/attachy/viewer/link_options_spec.rb +4 -2
- data/spec/models/attachy/viewer/link_spec.rb +4 -2
- data/spec/models/attachy/viewer/node_options_spec.rb +4 -2
- data/spec/models/attachy/viewer/node_spec.rb +2 -0
- data/spec/models/attachy/viewer/nodes_spec.rb +5 -3
- data/spec/models/attachy/viewer/remove_button_options_spec.rb +4 -2
- data/spec/models/attachy/viewer/transform_spec.rb +4 -2
- data/spec/models/attachy/viewer/value_spec.rb +8 -6
- data/spec/models/user_spec.rb +2 -0
- data/spec/support/common.rb +2 -0
- data/spec/support/database_cleaner.rb +2 -0
- data/spec/support/db/migrate/create_users_table.rb +2 -0
- data/spec/support/factory_girl.rb +2 -0
- data/spec/support/html_matchers.rb +2 -0
- data/spec/support/migrate.rb +2 -0
- data/spec/support/models/user.rb +2 -0
- data/spec/support/shoulda.rb +2 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac80ed2f422a74828c71af232340b5e37f091eb9
|
4
|
+
data.tar.gz: 70fca26a7ae273e3c91c2424b103984e88d00c3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f9159e3b620f5a67810d3d81ee76c5a9dd55cb2b8a51f2e427bfcd78383a46c17f97bd31a975e68245a580ce5b60edc551368d51c79f016ce047b179a44d9e3
|
7
|
+
data.tar.gz: 8d1d41a614f9e7bb6be422fd70cc0787a96255bf357173cd39c6eb9213cb4b2cb3f8c759e0a91271e6d4c828234c2585e0864e1715920bfd2590a13df0a63a19
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/attachy.rb
CHANGED
data/lib/attachy/engine.rb
CHANGED
data/lib/attachy/version.rb
CHANGED
@@ -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, [
|
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
|
data/spec/factories/user.rb
CHANGED
@@ -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 }.
|
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 }.
|
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 }.
|
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 }.
|
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,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: [
|
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: [
|
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,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 [
|
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
|
data/spec/models/user_spec.rb
CHANGED
data/spec/support/common.rb
CHANGED
data/spec/support/migrate.rb
CHANGED
data/spec/support/models/user.rb
CHANGED
data/spec/support/shoulda.rb
CHANGED
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.
|
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-
|
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
|
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
|
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
|
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
|
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.
|
313
|
+
rubygems_version: 2.6.11
|
314
314
|
signing_key:
|
315
315
|
specification_version: 4
|
316
316
|
summary: Attachments handler for Rails via Cloudinary.
|