rails-uploader 0.2.0 → 0.2.1

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.
data/README.md CHANGED
@@ -63,12 +63,13 @@ class Picture < Asset
63
63
  validates_filesize_of :data, :maximum => 2.megabytes.to_i
64
64
 
65
65
  # structure of returned json array of files. (used in Hash.to_json operation)
66
- def serializable_hash options=nil
66
+ def serializable_hash(options=nil)
67
67
  {
68
- 'id' => id.to_s,
68
+ "id" => id.to_s,
69
69
  "filename" => File.basename(data.path),
70
70
  "url" => data.url,
71
- 'thumb_url' => data.url(:thumb)
71
+ "thumb_url" => data.url(:thumb),
72
+ "public_token" => public_token
72
73
  }
73
74
  end
74
75
  end
@@ -129,43 +130,44 @@ class User
129
130
 
130
131
  fileuploads :picture, :avatar
131
132
  end
133
+ ```
132
134
 
133
135
 
134
136
  ### Include assets
135
137
 
136
138
  Javascripts:
137
139
 
138
- ``` ruby
140
+ ```
139
141
  //= require uploader/application
140
142
  ```
141
143
 
142
144
  Stylesheets:
143
145
 
144
- ``` ruby
146
+ ```
145
147
  *= require uploader/application
146
148
  ```
147
149
 
148
150
  ### Views
149
151
 
150
- ``` ruby
152
+ ```erb
151
153
  <%= uploader_field_tag :article, :photo %>
152
154
  ```
153
155
 
154
156
  or FormBuilder:
155
157
 
156
- ``` ruby
158
+ ```erb
157
159
  <%= form.uploader_field :photo, :sortable => true %>
158
160
  ```
159
161
 
160
162
  ### Formtastic
161
163
 
162
- ``` ruby
164
+ ```erb
163
165
  <%= f.input :pictures, :as => :uploader %>
164
166
  ```
165
167
 
166
168
  ### SimpleForm
167
169
 
168
- ``` ruby
170
+ ```erb
169
171
  <%= f.input :pictures, :as => :uploader, :input_html => {:sortable => true} %>
170
172
  ```
171
173
 
@@ -173,7 +175,7 @@ or FormBuilder:
173
175
 
174
176
  This is only working in Formtastic and FormBuilder:
175
177
 
176
- ``` ruby
178
+ ``` erb
177
179
  # formtastic
178
180
  <%= f.input :picture, :as => :uploader, :confirm_delete => true %>
179
181
  # the i18n lookup key would be en.formtastic.delete_confirmations.picture
@@ -3,10 +3,6 @@ module Uploader
3
3
  def self.included(base)
4
4
  base.send(:extend, Uploader::Asset::ClassMethods)
5
5
  base.send(:include, Uploader::Asset::AssetProcessor)
6
-
7
- base.instance_eval do
8
- before_create :generate_public_token
9
- end
10
6
  end
11
7
 
12
8
  module Mongoid
@@ -17,8 +13,6 @@ module Uploader
17
13
  base.instance_eval do
18
14
  field :guid, type: String
19
15
  field :public_token, type: String
20
-
21
- before_create :generate_public_token
22
16
  end
23
17
  end
24
18
 
@@ -1,3 +1,3 @@
1
1
  module Uploader
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
@@ -24,4 +24,6 @@ class Asset < ActiveRecord::Base
24
24
  include Uploader::Asset
25
25
 
26
26
  belongs_to :assetable, :polymorphic => true
27
+
28
+ before_create :generate_public_token
27
29
  end
@@ -2246,3 +2246,84 @@ Started POST "/uploader/attachments" for 127.0.0.1 at 2013-09-05 18:45:19 +0300
2246
2246
   (0.1ms) begin transaction
2247
2247
   (0.1ms) rollback transaction
2248
2248
  MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.4129ms)
2249
+ Connecting to database specified by database.yml
2250
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
2251
+ Migrating to CreateAssets (20120508093416)
2252
+ Migrating to CreateArticles (20120508093830)
2253
+  (0.1ms) begin transaction
2254
+  (0.1ms) SAVEPOINT active_record_1
2255
+ SQL (4.3ms) INSERT INTO "articles" ("content", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?) [["content", "MyText"], ["created_at", Sat, 07 Sep 2013 06:36:54 UTC +00:00], ["title", "MyString"], ["updated_at", Sat, 07 Sep 2013 06:36:54 UTC +00:00]]
2256
+  (0.1ms) RELEASE SAVEPOINT active_record_1
2257
+  (0.1ms) SAVEPOINT active_record_1
2258
+ Picture Exists (0.1ms) SELECT 1 AS one FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'AWt2HVkcENAITwiipl91' LIMIT 1
2259
+ SQL (0.7ms) INSERT INTO "assets" ("assetable_id", "assetable_type", "created_at", "data_content_type", "data_file_name", "data_file_size", "guid", "public_token", "type", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["assetable_id", 1], ["assetable_type", "Article"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["data_content_type", "image/png"], ["data_file_name", "rails.png"], ["data_file_size", nil], ["guid", nil], ["public_token", "AWt2HVkcENAITwiipl91"], ["type", "Picture"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["user_id", nil]]
2260
+  (0.1ms) RELEASE SAVEPOINT active_record_1
2261
+ Picture Load (0.3ms) SELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."guid" IS NULL AND "assets"."assetable_type" = 'Article' LIMIT 1
2262
+ SQL (0.2ms) UPDATE "assets" SET "assetable_id" = 1000, "guid" = NULL WHERE "assets"."type" IN ('Picture') AND "assets"."guid" IS NULL AND "assets"."assetable_type" = 'Article'
2263
+ Picture Load (0.1ms) SELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."id" = ? LIMIT 1 [["id", 1]]
2264
+ Picture Load (0.2ms) SELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."guid" = 'tERRDemHo1OMihKx3oBP' AND "assets"."assetable_type" = 'Article' LIMIT 1
2265
+  (0.1ms) SAVEPOINT active_record_1
2266
+  (0.0ms) RELEASE SAVEPOINT active_record_1
2267
+  (2.4ms) rollback transaction
2268
+ MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (21.0221ms)
2269
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (7.5850ms)
2270
+  (0.1ms) begin transaction
2271
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={"public_token"=>"gRMFvS8x2Rr0ec3iEXP8"} flags=[:slave_ok] limit=1 skip=0 fields={:_id=>1} (10.9842ms)
2272
+ MOPED: 127.0.0.1:27017 INSERT database=rails_uploader_test collection=mongoid_pictures documents=[{"_id"=>"522ac987dc26e7e3c4000001", "guid"=>"guid", "assetable_type"=>"MongoidArticle", "public_token"=>"gRMFvS8x2Rr0ec3iEXP8"}] flags=[] (0.1829ms)
2273
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={"$query"=>{"guid"=>"guid", "assetable_type"=>"MongoidArticle"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 fields=nil (28.3999ms)
2274
+ MOPED: 127.0.0.1:27017 COMMAND database=rails_uploader_test command={:count=>"mongoid_pictures", :query=>{}} (1.3881ms)
2275
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.3190ms)
2276
+ MOPED: 127.0.0.1:27017 DELETE database=rails_uploader_test collection=mongoid_pictures selector={"_id"=>"522ac987dc26e7e3c4000001"} flags=[:remove_first] (0.1488ms)
2277
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={"public_token"=>"ORqLAVteAhpTVGWHXOjC"} flags=[:slave_ok] limit=1 skip=0 fields={:_id=>1} (0.7150ms)
2278
+ MOPED: 127.0.0.1:27017 INSERT database=rails_uploader_test collection=mongoid_pictures documents=[{"_id"=>"522ac987dc26e7e3c4000002", "guid"=>"guid", "assetable_type"=>"MongoidArticle", "public_token"=>"ORqLAVteAhpTVGWHXOjC"}] flags=[] (0.1011ms)
2279
+ MOPED: 127.0.0.1:27017 UPDATE database=rails_uploader_test collection=mongoid_pictures selector={"guid"=>"guid", "assetable_type"=>"MongoidArticle"} update={"$set"=>{:assetable_id=>1000, :guid=>nil}} flags=[:multi] (0.1230ms)
2280
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={:_id=>"522ac987dc26e7e3c4000002"} flags=[:slave_ok] limit=-1 skip=0 fields=nil (3.6292ms)
2281
+ MOPED: 127.0.0.1:27017 COMMAND database=rails_uploader_test command={:count=>"mongoid_pictures", :query=>{}} (0.4101ms)
2282
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=mongoid_pictures selector={} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.2871ms)
2283
+ MOPED: 127.0.0.1:27017 DELETE database=rails_uploader_test collection=mongoid_pictures selector={"_id"=>"522ac987dc26e7e3c4000002"} flags=[:remove_first] (0.0710ms)
2284
+  (0.1ms) rollback transaction
2285
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.4151ms)
2286
+ MOPED: 127.0.0.1:27017 COMMAND database=rails_uploader_test command={:drop=>"mongoid_pictures"} (9.9230ms)
2287
+  (0.1ms) begin transaction
2288
+
2289
+
2290
+ Started POST "/uploader/attachments" for 127.0.0.1 at 2013-09-07 09:36:55 +0300
2291
+  (0.1ms) SAVEPOINT active_record_1
2292
+ Picture Exists (0.2ms) SELECT 1 AS one FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = '7PSgybt0d7BfJOUHdpve' LIMIT 1
2293
+ SQL (0.6ms) INSERT INTO "assets" ("assetable_id", "assetable_type", "created_at", "data_content_type", "data_file_name", "data_file_size", "guid", "public_token", "type", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["assetable_id", 1], ["assetable_type", "Article"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["data_content_type", nil], ["data_file_name", "rails.png"], ["data_file_size", nil], ["guid", "SOMESTRING"], ["public_token", "7PSgybt0d7BfJOUHdpve"], ["type", "Picture"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["user_id", nil]]
2294
+  (0.1ms) RELEASE SAVEPOINT active_record_1
2295
+  (0.1ms) SAVEPOINT active_record_1
2296
+ SQL (0.6ms) INSERT INTO "articles" ("content", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?) [["content", "MyText"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["title", "MyString"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00]]
2297
+  (0.0ms) RELEASE SAVEPOINT active_record_1
2298
+  (0.0ms) SAVEPOINT active_record_1
2299
+ Picture Exists (0.1ms) SELECT 1 AS one FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'dqTLYqXzmZOVibKNUmBn' LIMIT 1
2300
+ SQL (0.3ms) INSERT INTO "assets" ("assetable_id", "assetable_type", "created_at", "data_content_type", "data_file_name", "data_file_size", "guid", "public_token", "type", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["assetable_id", 1], ["assetable_type", "Article"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["data_content_type", "image/png"], ["data_file_name", "rails.png"], ["data_file_size", nil], ["guid", nil], ["public_token", "dqTLYqXzmZOVibKNUmBn"], ["type", "Picture"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["user_id", nil]]
2301
+  (0.1ms) RELEASE SAVEPOINT active_record_1
2302
+  (0.3ms) SELECT COUNT(*) FROM "assets" WHERE "assets"."type" IN ('Picture')
2303
+
2304
+
2305
+ Started DELETE "/uploader/attachments/dqTLYqXzmZOVibKNUmBn" for 127.0.0.1 at 2013-09-07 09:36:55 +0300
2306
+ Picture Load (0.2ms) SELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'dqTLYqXzmZOVibKNUmBn' LIMIT 1
2307
+  (0.0ms) SAVEPOINT active_record_1
2308
+ SQL (0.3ms) DELETE FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."id" = ? [["id", 2]]
2309
+  (0.1ms) RELEASE SAVEPOINT active_record_1
2310
+  (0.2ms) SELECT COUNT(*) FROM "assets" WHERE "assets"."type" IN ('Picture')
2311
+  (0.1ms) SAVEPOINT active_record_1
2312
+ SQL (0.5ms) INSERT INTO "articles" ("content", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?) [["content", "MyText"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["title", "MyString"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00]]
2313
+  (0.0ms) RELEASE SAVEPOINT active_record_1
2314
+  (0.0ms) SAVEPOINT active_record_1
2315
+ Picture Exists (0.1ms) SELECT 1 AS one FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'KHcKVIB0QJ0xDGYrOONx' LIMIT 1
2316
+ SQL (0.2ms) INSERT INTO "assets" ("assetable_id", "assetable_type", "created_at", "data_content_type", "data_file_name", "data_file_size", "guid", "public_token", "type", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["assetable_id", 2], ["assetable_type", "Article"], ["created_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["data_content_type", "image/png"], ["data_file_name", "rails.png"], ["data_file_size", nil], ["guid", nil], ["public_token", "KHcKVIB0QJ0xDGYrOONx"], ["type", "Picture"], ["updated_at", Sat, 07 Sep 2013 06:36:55 UTC +00:00], ["user_id", nil]]
2317
+  (0.0ms) RELEASE SAVEPOINT active_record_1
2318
+
2319
+
2320
+ Started DELETE "/uploader/attachments/wrong" for 127.0.0.1 at 2013-09-07 09:36:55 +0300
2321
+ Picture Load (0.1ms) SELECT "assets".* FROM "assets" WHERE "assets"."type" IN ('Picture') AND "assets"."public_token" = 'wrong' LIMIT 1
2322
+
2323
+
2324
+ Started POST "/uploader/attachments" for 127.0.0.1 at 2013-09-07 09:36:55 +0300
2325
+  (1.8ms) rollback transaction
2326
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.5319ms)
2327
+  (0.1ms) begin transaction
2328
+  (0.1ms) rollback transaction
2329
+ MOPED: 127.0.0.1:27017 QUERY database=rails_uploader_test collection=system.namespaces selector={:name=>{"$not"=>/system|\$/}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.4559ms)
data/spec/mongoid_spec.rb CHANGED
@@ -13,6 +13,8 @@ class MongoidPicture
13
13
  include Mongoid::Document
14
14
  include Uploader::Asset::Mongoid
15
15
 
16
+ before_create :generate_public_token
17
+
16
18
  belongs_to :assetable, polymorphic: true
17
19
  end
18
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-05 00:00:00.000000000 Z
13
+ date: 2013-09-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jquery-ui-rails