acts_as_assets 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/README.md +3 -0
  2. data/app/controllers/acts_as_assets/assets_controller.rb +48 -31
  3. data/app/helpers/acts_as_assets/assets_helper.rb +47 -4
  4. data/app/views/acts_as_assets/assets/_asset.html.erb +12 -0
  5. data/app/views/acts_as_assets/assets/_asset_multiple_upload.html.erb +6 -0
  6. data/app/views/acts_as_assets/assets/_asset_upload.html.erb +9 -0
  7. data/app/views/acts_as_assets/assets/_assets.html.erb +6 -0
  8. data/app/views/acts_as_assets/assets/_upload_link.html.erb +6 -0
  9. data/app/views/acts_as_assets/assets/create.js.erb +1 -1
  10. data/app/views/acts_as_assets/assets/destroy.js.erb +1 -1
  11. data/app/views/acts_as_assets/assets/index.html.erb +2 -12
  12. data/config/initializers/inflections.rb +14 -0
  13. data/config/locales/it.yml +2 -2
  14. data/lib/acts_as_assets/base.rb +66 -27
  15. data/lib/acts_as_assets/engine.rb +3 -0
  16. data/lib/acts_as_assets/form_helper.rb +42 -0
  17. data/lib/acts_as_assets/paperclip/interpolations.rb +1 -1
  18. data/lib/acts_as_assets/unique_asset.rb +4 -3
  19. data/lib/acts_as_assets/version.rb +1 -1
  20. data/spec/acts_as_assets_spec.rb +54 -52
  21. data/spec/controllers/assets_controller_spec.rb +21 -67
  22. data/spec/dummy/db/test.sqlite3 +0 -0
  23. data/spec/dummy/log/test.log +64789 -20346
  24. data/spec/routing/assets_routing_spec.rb +6 -0
  25. data/spec/spec_helper.rb +43 -17
  26. data/spec/support/book.rb +1 -2
  27. data/spec/support/chapter.rb +17 -0
  28. data/spec/support/chapters_assets_controller.rb +2 -0
  29. data/spec/support/tipi_pannello_assets_controller.rb +4 -0
  30. data/spec/support/tipo_pannello.rb +22 -0
  31. data/spec/unique_asset_spec.rb +4 -12
  32. metadata +85 -19
@@ -20,4 +20,10 @@ describe Books::AssetsController do
20
20
  it {should route(:get,'books/1/assets/get/20/filename.gif').to(
21
21
  :controller => "books/assets", :action => :get, :book_id => 1, :asset_id => 20, :filename => "filename", :extension => "gif")}
22
22
 
23
+ end
24
+
25
+ describe TipiPannello::AssetsController do
26
+ it {should route(:delete,'tipi_pannello/il_mio_tipo/assets/20.js').to(
27
+ :controller => "tipi_pannello/assets", :action => :destroy, :tipo_pannello_name=> 'il_mio_tipo', :format => 'js', :asset_id => 20)}
28
+
23
29
  end
@@ -12,7 +12,8 @@ require 'paperclip/matchers'
12
12
 
13
13
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
14
14
  ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
15
- Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
15
+
16
+ Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/*.rb")].each {|f| require f }
16
17
 
17
18
  require 'rspec/rails'
18
19
 
@@ -23,14 +24,35 @@ RSpec.configure do |config|
23
24
  config.mock_with :rspec
24
25
 
25
26
  config.before :suite do
26
- ActiveRecord::Base.connection.create_table(:books,:force => true) do |t|
27
+ ActiveRecord::Base.connection.create_table(:books, :force => true) do |t|
27
28
  t.string :title
28
29
  end
29
- ActiveRecord::Base.connection.create_table(:books_assets,:force => true) do |t|
30
+ ActiveRecord::Base.connection.create_table(:books_assets, :force => true) do |t|
30
31
  t.has_attached_file :asset
31
32
  t.string :type
32
33
  t.integer :counter, :default => 0, :null => false
33
34
  t.integer :book_id
35
+ t.boolean :displayable, :default => false, :null => false
36
+ end
37
+ ActiveRecord::Base.connection.create_table(:chapters, {:id => false, :force => true}) do |t|
38
+ t.string :name, :null => false
39
+ end
40
+ ActiveRecord::Base.connection.create_table(:chapters_assets, :force => true) do |t|
41
+ t.has_attached_file :asset
42
+ t.string :type
43
+ t.integer :counter, :default => 0, :null => false
44
+ t.string :chapter_name
45
+ t.boolean :displayable, :default => false, :null => false
46
+ end
47
+ ActiveRecord::Base.connection.create_table(:rt_tipi_pannello, {:id => false, :force => true}) do |t|
48
+ t.string :name, :null => false
49
+ end
50
+ ActiveRecord::Base.connection.create_table(:rt_tipi_pannello_assets, :force => true) do |t|
51
+ t.has_attached_file :asset
52
+ t.string :type
53
+ t.integer :counter, :default => 0, :null => false
54
+ t.boolean :displayable, :default => false, :null => false
55
+ t.string :tipo_pannello_name
34
56
  end
35
57
  Rails.application.routes.draw do
36
58
  scope "books/:book_id/assets/" do
@@ -39,20 +61,26 @@ RSpec.configure do |config|
39
61
  post '*type' => 'books/assets#create', :as => 'book_create_asset'
40
62
  delete ':asset_id' => 'books/assets#destroy', :as => 'book_destroy_asset'
41
63
  end
64
+ scope "chapters/:chapter_name/assets/", :chapter_name => /.*/ do
65
+ get 'get/:asset_id/(:style)/:filename.:extension' => 'chapters/assets#get', :as => 'chapter_get_asset'
66
+ get '*type' => 'chapters/assets#index', :as => 'chapter_assets'
67
+ post '*type' => 'chapters/assets#create', :as => 'chapter_create_asset'
68
+ delete ':asset_id' => 'chapters/assets#destroy', :as => 'chapter_destroy_asset'
69
+ end
70
+ scope "tipi_pannello/:tipo_pannello_name/assets/" do
71
+ get 'get/:asset_id/(:style)/:filename.:extension' => 'tipi_pannello/assets#get', :as => 'tipo_pannello_get_asset'
72
+ get '*type' => 'tipi_pannello/assets#index', :as => 'tipo_pannello_assets'
73
+ post '*type' => 'tipi_pannello/assets#create', :as => 'tipo_pannello_create_asset'
74
+ delete ':asset_id' => 'tipi_pannello/assets#destroy', :as => 'tipo_pannello_destroy_asset'
75
+ end
42
76
  end
43
-
44
77
  end
45
78
 
46
- #destroy created assets
47
- config.before :all do
48
- @dtbd = []
49
- end
50
- config.after :all do
79
+ config.after :suite do
51
80
  require 'fileutils'
52
- @dtbd.each {|d| d.destroy unless d.nil? }
53
- Dir[File.expand_path("spec/temp/*")].each do |file|
54
- FileUtils.rm file
55
- end
81
+ Dir[File.expand_path("../public/*", __FILE__)].each {|file| FileUtils.rm_rf file }
82
+ Dir[File.expand_path("../temp/*", __FILE__)].each {|file| FileUtils.rm_rf file }
83
+ puts "Cleaned up files"
56
84
  end
57
85
 
58
86
  config.before(:each) do
@@ -61,11 +89,9 @@ RSpec.configure do |config|
61
89
  Book.delete_all
62
90
  end
63
91
 
64
- config.after(:suite) do
65
- end
66
-
67
- def jpg_test
92
+ def uploaded_test_asset
68
93
  Rack::Test::UploadedFile.new(File.expand_path('../resources/jpg_test.jpg',__FILE__), "image/jpeg")
69
94
  end
70
95
 
96
+ #def uploader_field_tag(name, *args); end
71
97
  end
@@ -36,5 +36,4 @@ module Books
36
36
  class TestImage < Books::Image
37
37
  end
38
38
  end
39
- end
40
-
39
+ end
@@ -0,0 +1,17 @@
1
+ class Chapter < ActiveRecord::Base
2
+ self.primary_key = :name
3
+ attr_accessible :id, :name
4
+ has_one :assets, :class_name => "Chapters::Asset", :foreign_key => "chapter_name"
5
+ end
6
+ module Chapters
7
+ class Asset < ActiveRecord::Base
8
+ self.table_name = "chapters_assets"
9
+ acts_as_assets :foreign_key => "chapter_name"
10
+ end
11
+ end
12
+ module Chapters
13
+ module Assets
14
+ class Paragraph < Chapters::Asset
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ class Chapters::AssetsController < ActsAsAssets::AssetsController
2
+ end
@@ -0,0 +1,4 @@
1
+ module TipiPannello
2
+ class AssetsController < ActsAsAssets::AssetsController
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ class TipoPannello < ActiveRecord::Base
2
+ self.primary_key = :name
3
+ self.table_name = :rt_tipi_pannello
4
+ has_one :asset_scheda_tecnica, :class_name => "TipiPannello::Documenti"
5
+ has_one :scheda_tecnica, :class_name => "TipiPannello::Documenti::SchedaTecnica", :through => :asset_scheda_tecnica
6
+ attr_accessible :id, :name
7
+ end
8
+
9
+ module TipiPannello
10
+ class Asset < ActiveRecord::Base
11
+ self.table_name_prefix = :rt_tipi_pannello_
12
+ acts_as_assets :foreign_key => :tipo_pannello_name
13
+ end
14
+ end
15
+
16
+ module TipiPannello
17
+ module Documenti
18
+ class SchedaTecnica < TipiPannello::Asset
19
+ include ActsAsAssets::UniqueAsset
20
+ end
21
+ end
22
+ end
@@ -4,17 +4,11 @@ describe ActsAsAssets::UniqueAsset do
4
4
  let(:book) { Book.create!(:title => "my new book") }
5
5
 
6
6
  context "creating 2 assets of the same type related to the same resource" do
7
- before do
8
- @book = book
9
- end
10
-
11
7
  context "and asset include the model UniqAsset" do
12
8
 
13
9
  it "should fail on the creation of the second asset" do
14
- asset1 = Books::Assets::UniqueTestDoc.create! :book => @book
15
- @dtbd << asset1
16
- asset2 = Books::Assets::UniqueTestDoc.new :book => @book
17
- @dtbd << asset2
10
+ Books::Assets::UniqueTestDoc.create! :book => book
11
+ asset2 = Books::Assets::UniqueTestDoc.new :book => book
18
12
  asset2.save
19
13
 
20
14
  asset2.should_not be_valid
@@ -26,10 +20,8 @@ describe ActsAsAssets::UniqueAsset do
26
20
  context "and asset does not include the model UniqAsset" do
27
21
 
28
22
  it "should fail on the creation of the second asset" do
29
- asset1 = Books::Assets::TestDoc.create! :book => @book
30
- @dtbd << asset1
31
- asset2 = Books::Assets::TestDoc.new :book => @book
32
- @dtbd << asset2
23
+ asset1 = Books::Assets::TestDoc.create! :book => book
24
+ asset2 = Books::Assets::TestDoc.new :book => book
33
25
  asset2.save
34
26
 
35
27
  asset2.should be_valid
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000Z
12
+ date: 2012-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70331742182940 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,31 @@ dependencies:
21
21
  version: 3.2.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70331742182940
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.1
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: paperclip
27
- requirement: &70331742182280 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: h5_uploader
48
+ requirement: !ruby/object:Gem::Requirement
28
49
  none: false
29
50
  requirements:
30
51
  - - ! '>='
@@ -32,10 +53,15 @@ dependencies:
32
53
  version: '0'
33
54
  type: :runtime
34
55
  prerelease: false
35
- version_requirements: *70331742182280
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
36
62
  - !ruby/object:Gem::Dependency
37
63
  name: ci_reporter
38
- requirement: &70331742181480 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
39
65
  none: false
40
66
  requirements:
41
67
  - - ! '>='
@@ -43,10 +69,15 @@ dependencies:
43
69
  version: '0'
44
70
  type: :development
45
71
  prerelease: false
46
- version_requirements: *70331742181480
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
47
78
  - !ruby/object:Gem::Dependency
48
79
  name: sqlite3
49
- requirement: &70331742180800 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
50
81
  none: false
51
82
  requirements:
52
83
  - - ! '>='
@@ -54,10 +85,15 @@ dependencies:
54
85
  version: '0'
55
86
  type: :development
56
87
  prerelease: false
57
- version_requirements: *70331742180800
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
58
94
  - !ruby/object:Gem::Dependency
59
95
  name: rspec-rails
60
- requirement: &70331742180160 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
61
97
  none: false
62
98
  requirements:
63
99
  - - ! '>='
@@ -65,10 +101,15 @@ dependencies:
65
101
  version: '0'
66
102
  type: :development
67
103
  prerelease: false
68
- version_requirements: *70331742180160
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
69
110
  - !ruby/object:Gem::Dependency
70
111
  name: paperclip
71
- requirement: &70331742178240 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
72
113
  none: false
73
114
  requirements:
74
115
  - - ! '>='
@@ -76,10 +117,15 @@ dependencies:
76
117
  version: '0'
77
118
  type: :development
78
119
  prerelease: false
79
- version_requirements: *70331742178240
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
80
126
  - !ruby/object:Gem::Dependency
81
127
  name: shoulda-matchers
82
- requirement: &70331742176820 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
83
129
  none: false
84
130
  requirements:
85
131
  - - ! '>='
@@ -87,7 +133,12 @@ dependencies:
87
133
  version: '0'
88
134
  type: :development
89
135
  prerelease: false
90
- version_requirements: *70331742176820
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
91
142
  description: Manage multiple assets related to a specific model
92
143
  email:
93
144
  - acampolonghi@gmail.com
@@ -97,13 +148,20 @@ extra_rdoc_files: []
97
148
  files:
98
149
  - app/controllers/acts_as_assets/assets_controller.rb
99
150
  - app/helpers/acts_as_assets/assets_helper.rb
151
+ - app/views/acts_as_assets/assets/_asset.html.erb
152
+ - app/views/acts_as_assets/assets/_asset_multiple_upload.html.erb
153
+ - app/views/acts_as_assets/assets/_asset_upload.html.erb
154
+ - app/views/acts_as_assets/assets/_assets.html.erb
155
+ - app/views/acts_as_assets/assets/_upload_link.html.erb
100
156
  - app/views/acts_as_assets/assets/create.js.erb
101
157
  - app/views/acts_as_assets/assets/destroy.js.erb
102
158
  - app/views/acts_as_assets/assets/index.html.erb
159
+ - config/initializers/inflections.rb
103
160
  - config/locales/it.yml
104
161
  - config/routes.rb
105
162
  - lib/acts_as_assets/base.rb
106
163
  - lib/acts_as_assets/engine.rb
164
+ - lib/acts_as_assets/form_helper.rb
107
165
  - lib/acts_as_assets/matchers/rspec.rb
108
166
  - lib/acts_as_assets/paperclip/interpolations.rb
109
167
  - lib/acts_as_assets/unique_asset.rb
@@ -151,6 +209,10 @@ files:
151
209
  - spec/spec_helper.rb
152
210
  - spec/support/book.rb
153
211
  - spec/support/books_assets_controller.rb
212
+ - spec/support/chapter.rb
213
+ - spec/support/chapters_assets_controller.rb
214
+ - spec/support/tipi_pannello_assets_controller.rb
215
+ - spec/support/tipo_pannello.rb
154
216
  - spec/unique_asset_spec.rb
155
217
  homepage: ''
156
218
  licenses: []
@@ -166,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
228
  version: '0'
167
229
  segments:
168
230
  - 0
169
- hash: 723916665890432220
231
+ hash: 835702223512288152
170
232
  required_rubygems_version: !ruby/object:Gem::Requirement
171
233
  none: false
172
234
  requirements:
@@ -175,10 +237,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
237
  version: '0'
176
238
  segments:
177
239
  - 0
178
- hash: 723916665890432220
240
+ hash: 835702223512288152
179
241
  requirements: []
180
242
  rubyforge_project:
181
- rubygems_version: 1.8.10
243
+ rubygems_version: 1.8.21
182
244
  signing_key:
183
245
  specification_version: 3
184
246
  summary: Assets management
@@ -222,4 +284,8 @@ test_files:
222
284
  - spec/spec_helper.rb
223
285
  - spec/support/book.rb
224
286
  - spec/support/books_assets_controller.rb
287
+ - spec/support/chapter.rb
288
+ - spec/support/chapters_assets_controller.rb
289
+ - spec/support/tipi_pannello_assets_controller.rb
290
+ - spec/support/tipo_pannello.rb
225
291
  - spec/unique_asset_spec.rb