attachy 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +35 -15
- data/lib/assets/javascripts/attachy.js +1 -1
- data/lib/attachy/models/attachy/extension.rb +2 -0
- data/lib/attachy/version.rb +1 -1
- data/spec/models/attachy/extension/user/avatar_spec.rb +120 -8
- data/spec/models/attachy/extension/user/photos_spec.rb +120 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c10bc66de882f1201aba52a87e64c5ac48e46a34
|
4
|
+
data.tar.gz: fc2c4995faa82011745592e90dc0ab9387571a05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611a2c9b85a28674a0a026719bc743bbdc37774502ce87c3676732e651a60b87ca6463abb74c6334cf0ad3a3c03f9d0b83898b35f7ae2bbb023569cc0772bb3e
|
7
|
+
data.tar.gz: ab8e16ae400ee56ec645d18acd1cdbd52e9ce3ceffb3f85ac2e4f8f50306e86ffa19278afb04021228e8b58caf623ae1d4d4fe3904e16ba026c945f6b9dbdd3e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Attachy
|
2
2
|
|
3
|
-
Attachments handler for Rails via
|
3
|
+
Attachments handler for Rails via http://cloudinary.com
|
4
4
|
|
5
|
-
##
|
5
|
+
## Description
|
6
6
|
|
7
7
|
Send files from your browser directly to Cloudinary.
|
8
8
|
Attachy will generate a `has_one` or `has_many` files (photos) to your model
|
@@ -48,42 +48,34 @@ end
|
|
48
48
|
Expose your Cloudinary credentials on your layout:
|
49
49
|
|
50
50
|
```html
|
51
|
-
<%= cloudinary_js_config %>
|
51
|
+
<%= cloudinary_js_config %>
|
52
52
|
```
|
53
53
|
|
54
|
-
Into your form the upload field:
|
54
|
+
Into your form, add the upload field:
|
55
55
|
|
56
56
|
```html
|
57
57
|
<%= f.attachy :avatar %>
|
58
58
|
```
|
59
59
|
|
60
|
-
If you want just show your uploaded image, use:
|
61
|
-
|
62
|
-
```html
|
63
|
-
<%= attachy_link :avatar, @object %>
|
64
|
-
```
|
65
|
-
|
66
|
-
It will generate a link to your image with the image inside.
|
67
|
-
|
68
60
|
### Assets
|
69
61
|
|
70
62
|
Includes the `attachy.js` on your js manifest:
|
71
63
|
|
72
64
|
```js
|
73
|
-
//= require
|
65
|
+
//= require attachy
|
74
66
|
```
|
75
67
|
|
76
68
|
Includes the `attachy.sass` on your css manifest:
|
77
69
|
|
78
70
|
```js
|
79
71
|
/*
|
80
|
-
*= require
|
72
|
+
*= require attachy
|
81
73
|
*/
|
82
74
|
```
|
83
75
|
|
84
76
|
### <a name="default-image"></a> Configurations
|
85
77
|
|
86
|
-
On your `attachy.yml` configure a default image to show when model has no
|
78
|
+
On your `attachy.yml` you can configure a default image to show when model has no file attached:
|
87
79
|
|
88
80
|
```js
|
89
81
|
format: jpg
|
@@ -91,6 +83,34 @@ public_id: default
|
|
91
83
|
version: 42
|
92
84
|
```
|
93
85
|
|
86
|
+
## Showing
|
87
|
+
|
88
|
+
If you want just show your uploaded image, use:
|
89
|
+
|
90
|
+
```html
|
91
|
+
<%= attachy_link :avatar, @object %>
|
92
|
+
```
|
93
|
+
|
94
|
+
It will generate a link to your image with the image inside.
|
95
|
+
|
96
|
+
## Transformation
|
97
|
+
|
98
|
+
You can manipulate the image using the `t` attribute:
|
99
|
+
|
100
|
+
```
|
101
|
+
<%= f.attachy :avatar, t: { width: 160, height: 160, crop: :fill } %>
|
102
|
+
```
|
103
|
+
|
104
|
+
To know more about transformations, check the [Cloudinary Doc](http://cloudinary.com/documentation/image_transformations).
|
105
|
+
|
106
|
+
## HTML
|
107
|
+
|
108
|
+
For HTML attributes, just use `html`:
|
109
|
+
|
110
|
+
```
|
111
|
+
<%= f.attachy :avatar, html: { width: 160, height: 160, alt: 'Image' } %>
|
112
|
+
```
|
113
|
+
|
94
114
|
## Test
|
95
115
|
|
96
116
|
Before send pull request, check if specs is passing.
|
data/lib/attachy/version.rb
CHANGED
@@ -17,22 +17,26 @@ RSpec.describe User, ':avatar' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe ':avatar_files=' do
|
20
|
-
let!(:user)
|
21
|
-
let!(:avatar_1) { create :file, scope: :avatar }
|
22
|
-
let!(:avatar_2) { create :file, scope: :avatar }
|
20
|
+
let!(:user) { create :user }
|
23
21
|
|
24
22
|
context 'when given records' do
|
25
|
-
|
23
|
+
context 'already persisted' do
|
24
|
+
let!(:avatar_1) { create :file, scope: :avatar }
|
25
|
+
let!(:avatar_2) { create :file, scope: :avatar }
|
26
|
+
|
27
|
+
before { user.avatar_files = [avatar_1, avatar_2] }
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
+
it 'references all' do
|
30
|
+
expect(user.avatar_files).to match_array [avatar_1, avatar_2]
|
31
|
+
end
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
35
|
context 'when given no records' do
|
33
|
-
|
36
|
+
let!(:avatar_1) { create :file, scope: :avatar, attachable: user }
|
37
|
+
let!(:avatar_2) { create :file, scope: :avatar, attachable: user }
|
34
38
|
|
35
|
-
it 'clears
|
39
|
+
it 'clears all' do
|
36
40
|
user.avatar_files = []
|
37
41
|
|
38
42
|
expect(user.avatar_files).to eq []
|
@@ -63,6 +67,114 @@ RSpec.describe User, ':avatar' do
|
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
70
|
+
describe ':avatar=' do
|
71
|
+
let!(:user) { create :user }
|
72
|
+
|
73
|
+
context 'with persisted record' do
|
74
|
+
let!(:avatar) { create :file, scope: :avatar }
|
75
|
+
|
76
|
+
context 'as a json' do
|
77
|
+
let!(:json) { avatar.to_json }
|
78
|
+
|
79
|
+
it 'does not creates a new one' do
|
80
|
+
user.avatar = json
|
81
|
+
|
82
|
+
expect { user.avatar_files }.to_not change(Attachy::File, :count)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'is referenced' do
|
86
|
+
user.avatar = json
|
87
|
+
|
88
|
+
expect(user.avatar_files).to eq [avatar]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'as an array of json' do
|
93
|
+
let!(:json) { [avatar].to_json }
|
94
|
+
|
95
|
+
it 'does not creates a new one' do
|
96
|
+
user.avatar = json
|
97
|
+
|
98
|
+
expect { user.avatar_files }.to_not change(Attachy::File, :count)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'is referenced' do
|
102
|
+
user.avatar = json
|
103
|
+
|
104
|
+
expect(user.avatar_files).to eq [avatar]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'with no persisted record' do
|
110
|
+
let!(:avatar) do
|
111
|
+
build(:file,
|
112
|
+
format: :jpg,
|
113
|
+
height: 600,
|
114
|
+
public_id: :public_id,
|
115
|
+
scope: :avatar,
|
116
|
+
width: 800
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'as a json' do
|
121
|
+
let!(:json) { avatar.to_json }
|
122
|
+
|
123
|
+
it 'is saved and referenced' do
|
124
|
+
user.avatar = json
|
125
|
+
|
126
|
+
expect(user.avatar_files.size).to eq 1
|
127
|
+
|
128
|
+
file = user.avatar_files[0]
|
129
|
+
|
130
|
+
expect(file.format).to eq 'jpg'
|
131
|
+
expect(file.height).to eq 600
|
132
|
+
expect(file.public_id).to eq 'public_id'
|
133
|
+
expect(file.scope).to eq 'avatar'
|
134
|
+
expect(file.width).to eq 800
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'as an array of json' do
|
139
|
+
let!(:json) { [avatar].to_json }
|
140
|
+
|
141
|
+
it 'is saved and referenced' do
|
142
|
+
user.avatar = json
|
143
|
+
|
144
|
+
expect(user.avatar_files.size).to eq 1
|
145
|
+
|
146
|
+
file = user.avatar_files[0]
|
147
|
+
|
148
|
+
expect(file.format).to eq 'jpg'
|
149
|
+
expect(file.height).to eq 600
|
150
|
+
expect(file.public_id).to eq 'public_id'
|
151
|
+
expect(file.scope).to eq 'avatar'
|
152
|
+
expect(file.width).to eq 800
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'with an empty string' do
|
158
|
+
let!(:avatar) { create :file, scope: :avatar, attachable: user }
|
159
|
+
|
160
|
+
it 'does nothing' do
|
161
|
+
user.avatar = ''
|
162
|
+
|
163
|
+
expect(user.avatar_files).to eq [avatar]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'with an empty array as string' do
|
168
|
+
let!(:avatar) { create :file, scope: :avatar, attachable: user }
|
169
|
+
|
170
|
+
it 'clears the records' do
|
171
|
+
user.avatar = '[]'
|
172
|
+
|
173
|
+
expect(user.avatar_files).to eq []
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
66
178
|
describe ':avatar?' do
|
67
179
|
let!(:user) { create :user }
|
68
180
|
|
@@ -17,22 +17,26 @@ RSpec.describe User, ':photos' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe ':photos_files=' do
|
20
|
-
let!(:user)
|
21
|
-
let!(:photo_1) { create :file, scope: :photo }
|
22
|
-
let!(:photo_2) { create :file, scope: :photo }
|
20
|
+
let!(:user) { create :user }
|
23
21
|
|
24
22
|
context 'when given records' do
|
25
|
-
|
23
|
+
context 'already persisted' do
|
24
|
+
let!(:photo_1) { create :file, scope: :photos }
|
25
|
+
let!(:photo_2) { create :file, scope: :photos }
|
26
|
+
|
27
|
+
before { user.photos_files = [photo_1, photo_2] }
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
+
it 'references all' do
|
30
|
+
expect(user.photos_files).to match_array [photo_1, photo_2]
|
31
|
+
end
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
35
|
context 'when given no records' do
|
33
|
-
|
36
|
+
let!(:photo_1) { create :file, scope: :photo, attachable: user }
|
37
|
+
let!(:photo_2) { create :file, scope: :photo, attachable: user }
|
34
38
|
|
35
|
-
it 'clears
|
39
|
+
it 'clears all' do
|
36
40
|
user.photos_files = []
|
37
41
|
|
38
42
|
expect(user.photos_files).to eq []
|
@@ -59,6 +63,114 @@ RSpec.describe User, ':photos' do
|
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
66
|
+
describe ':photos=' do
|
67
|
+
let!(:user) { create :user }
|
68
|
+
|
69
|
+
context 'with persisted record' do
|
70
|
+
let!(:photo) { create :file, scope: :photos }
|
71
|
+
|
72
|
+
context 'as a json' do
|
73
|
+
let!(:json) { photo.to_json }
|
74
|
+
|
75
|
+
it 'does not creates a new one' do
|
76
|
+
user.photos = json
|
77
|
+
|
78
|
+
expect { user.photos_files }.to_not change(Attachy::File, :count)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'is referenced' do
|
82
|
+
user.photos = json
|
83
|
+
|
84
|
+
expect(user.photos_files).to eq [photo]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'as an array of json' do
|
89
|
+
let!(:json) { [photo].to_json }
|
90
|
+
|
91
|
+
it 'does not creates a new one' do
|
92
|
+
user.photos = json
|
93
|
+
|
94
|
+
expect { user.photos_files }.to_not change(Attachy::File, :count)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'is referenced' do
|
98
|
+
user.photos = json
|
99
|
+
|
100
|
+
expect(user.photos_files).to eq [photo]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'with no persisted record' do
|
106
|
+
let!(:photo) do
|
107
|
+
build(:file,
|
108
|
+
format: :jpg,
|
109
|
+
height: 600,
|
110
|
+
public_id: :public_id,
|
111
|
+
scope: :photo,
|
112
|
+
width: 800
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'as a json' do
|
117
|
+
let!(:json) { photo.to_json }
|
118
|
+
|
119
|
+
it 'is saved and referenced' do
|
120
|
+
user.photos = json
|
121
|
+
|
122
|
+
expect(user.photos_files.size).to eq 1
|
123
|
+
|
124
|
+
file = user.photos_files[0]
|
125
|
+
|
126
|
+
expect(file.format).to eq 'jpg'
|
127
|
+
expect(file.height).to eq 600
|
128
|
+
expect(file.public_id).to eq 'public_id'
|
129
|
+
expect(file.scope).to eq 'photos'
|
130
|
+
expect(file.width).to eq 800
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'as an array of json' do
|
135
|
+
let!(:json) { [photo].to_json }
|
136
|
+
|
137
|
+
it 'is saved and referenced' do
|
138
|
+
user.photos = json
|
139
|
+
|
140
|
+
expect(user.photos_files.size).to eq 1
|
141
|
+
|
142
|
+
file = user.photos_files[0]
|
143
|
+
|
144
|
+
expect(file.format).to eq 'jpg'
|
145
|
+
expect(file.height).to eq 600
|
146
|
+
expect(file.public_id).to eq 'public_id'
|
147
|
+
expect(file.scope).to eq 'photos'
|
148
|
+
expect(file.width).to eq 800
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'with an empty string' do
|
154
|
+
let!(:photo) { create :file, scope: :photos, attachable: user }
|
155
|
+
|
156
|
+
it 'does nothing' do
|
157
|
+
user.photos = ''
|
158
|
+
|
159
|
+
expect(user.photos_files).to eq [photo]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'with an empty array as string' do
|
164
|
+
let!(:photo) { create :file, scope: :photo, attachable: user }
|
165
|
+
|
166
|
+
it 'clears the records' do
|
167
|
+
user.photos = '[]'
|
168
|
+
|
169
|
+
expect(user.photos_files).to eq []
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
62
174
|
describe ':photo?' do
|
63
175
|
let!(:user) { create :user }
|
64
176
|
|
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cloudinary
|