lolita-file-upload 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.document +5 -5
  2. data/.rspec +2 -2
  3. data/Gemfile +21 -21
  4. data/LICENSE.txt +20 -20
  5. data/README.rdoc +27 -27
  6. data/Rakefile +39 -39
  7. data/VERSION +1 -1
  8. data/app/controllers/lolita/uploads_controller.rb +58 -0
  9. data/app/models/lolita/upload/file.rb +43 -43
  10. data/app/uploaders/file_uploader.rb +20 -20
  11. data/app/views/components/lolita/configuration/tab/files/_cells.html.erb +10 -4
  12. data/app/views/components/lolita/configuration/tab/files/_destroy.js.erb +2 -2
  13. data/app/views/components/lolita/configuration/tab/files/_display.html.erb +10 -11
  14. data/app/views/components/lolita/configuration/tab/files/_edit.js.erb +1 -1
  15. data/app/views/components/lolita/configuration/tab/files/_file.html.erb +5 -0
  16. data/app/views/components/lolita/configuration/tab/files/_fixed_gallery.html.haml +33 -0
  17. data/app/views/components/lolita/configuration/tab/files/_form.html.erb +7 -3
  18. data/app/views/components/lolita/configuration/tab/files/_list.html.erb +13 -13
  19. data/app/views/components/lolita/configuration/tab/files/_list_form.html.erb +5 -5
  20. data/app/views/components/lolita/configuration/tab/files/_row.html.erb +5 -2
  21. data/app/views/components/lolita/configuration/tab/files/_update.js.erb +1 -1
  22. data/app/views/components/lolita/configuration/tab/files/_upload_script.html.erb +79 -77
  23. data/config/locales/en.yml +18 -18
  24. data/features/configuration_for_tab.feature +25 -25
  25. data/features/connect_with_lolita.feature +14 -14
  26. data/features/extend_resources_with_new_routes.feature +16 -16
  27. data/features/step_definitions/lolita_steps.rb +112 -112
  28. data/features/support/env.rb +15 -15
  29. data/features/support_byte_converter.feature +31 -31
  30. data/features/upload_file.feature +15 -15
  31. data/lib/generators/lolita_file_upload/assets_generator.rb +12 -12
  32. data/lib/generators/lolita_file_upload/install_generator.rb +19 -19
  33. data/lib/generators/lolita_file_upload/templates/migration.rb +24 -24
  34. data/lib/lolita-file-upload.rb +35 -36
  35. data/lib/lolita-file-upload/configuration/tab/files.rb +108 -57
  36. data/lib/lolita-file-upload/module.rb +10 -6
  37. data/lib/lolita-file-upload/rails.rb +7 -7
  38. data/lib/lolita-file-upload/rails/file_upload_routes.rb +14 -19
  39. data/lib/support/bytes.rb +58 -58
  40. data/lolita-file-upload.gemspec +9 -13
  41. data/public/javascripts/lolita/upload/I18n/lv.js +21 -21
  42. data/public/javascripts/lolita/upload/I18n/ru.js +21 -21
  43. data/public/javascripts/lolita/upload/plupload.full.js +1 -1
  44. data/public/stylesheets/lolita/upload/jquery.ui.plupload.css +139 -139
  45. data/public/stylesheets/lolita/upload/plupload.queue.css +177 -177
  46. data/spec/configuration/tab/files_spec.rb +36 -36
  47. data/spec/lolita/support/bytes_spec.rb +35 -35
  48. data/spec/models/file_spec.rb +33 -33
  49. data/spec/spec_helper.rb +32 -29
  50. data/spec/support/post.rb +2 -2
  51. data/spec/uploaders/file_uploader_spec.rb +11 -11
  52. data/test_orm/active_record.rb +11 -11
  53. data/test_orm/active_record/news.rb +11 -11
  54. data/test_orm/active_record/post.rb +12 -12
  55. data/test_orm/active_record/tag.rb +2 -2
  56. data/test_orm/config/active_record.yml +1 -1
  57. data/test_orm/coverage.rb +18 -18
  58. data/test_orm/db/migrate/01_create_posts.rb +14 -14
  59. data/test_orm/db/migrate/02_create_files.rb +19 -19
  60. data/test_orm/db/migrate/03_create_news.rb +16 -16
  61. data/test_orm/db/migrate/04_create_tags.rb +14 -14
  62. data/test_orm/files/large_file.txt +201 -201
  63. data/test_orm/files/normal_file.txt +1 -1
  64. data/test_orm/rails/config/application.rb +7 -7
  65. data/test_orm/rails/config/enviroment.rb +4 -4
  66. data/test_orm/rails/config/routes.rb +2 -2
  67. data/test_orm/rails/log/development.log +7 -7
  68. data/test_orm/support.rb +26 -26
  69. data/test_orm/uploaders/list_image_uploader.rb +5 -5
  70. data/test_orm/uploaders/main_image_uploader.rb +5 -5
  71. metadata +19 -23
  72. data/app/controllers/lolita/upload/files_controller.rb +0 -51
  73. data/app/controllers/lolita/upload/images_controller.rb +0 -52
  74. data/lib/lolita-file-upload/configuration/tab/images.rb +0 -20
  75. data/spec/configuration/tab/images_spec.rb +0 -16
  76. data/upload/lolita/upload/file/201105/1/large_file.txt +0 -201
  77. data/upload/lolita/upload/file/201106/1/large_file.txt +0 -201
  78. data/upload/misc/large_file.txt +0 -201
@@ -1,11 +1,10 @@
1
- <%= form_tag(send(:"lolita_upload_#{tab.type}_path"),:method=>:post, :id=>"#{tab.type}_form") do %>
2
- <div id="file_upload_container">
3
- Your bowser don't have HTML5 or Flash support.
4
- </div>
5
- <% end %>
6
- <div id="filelist">
7
- <%= render_component tab,:list %>
8
- </div>
9
- <%= render_component tab, :upload_script, :container => "file_upload_container"%>
10
- <%= render_component :"lolita/configuration/tab", :fields, :tab=>tab %>
11
-
1
+ <%= form_tag(send(:"create_upload_lolita_#{tab.dbi.klass.model_name.plural.downcase}_path", :association => tab.association.name),:method=>:post, :id=>"#{tab.association.name}_form") do %>
2
+ <div id="file_upload_container_<%="#{tab.association.name}"%>">
3
+ Your bowser don't have HTML5 or Flash support.
4
+ </div>
5
+ <% end %>
6
+ <div id="filelist">
7
+ <%= render_component tab,:list %>
8
+ </div>
9
+ <%= render_component tab, :upload_script, :container => "file_upload_container_#{tab.association.name}"%>
10
+ <%= render_component :"lolita/configuration/tab", :fields, :tab=>tab %>
@@ -1 +1 @@
1
- $("#upload_<%=tab.type%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(*tab.build("",:list_form,:file=>file,:format=>"html")))%>")
1
+ $("#upload_<%=tab.association.name%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(*tab.build("",:list_form,:file=>file,:format=>"html")))%>");
@@ -0,0 +1,5 @@
1
+ <% if file.send(tab.uploader).to_s =~ /(jpg|jpeg|png|gif)$/i %>
2
+ <%= link_to image_tag(file.send(tab.uploader).url), file.send(tab.uploader).url %>
3
+ <% else %>
4
+ <%= link_to file.send(tab.uploader).url, file.send(tab.uploader).url %>
5
+ <% end %>
@@ -0,0 +1,33 @@
1
+ :css
2
+ #fixed-gallery {
3
+ position: fixed;
4
+ top: 0px;
5
+ left: 0px;
6
+ border-bottom: 4px solid #CCC;
7
+ background-color: white;
8
+ z-index: 200001;
9
+ width: 100%;
10
+ display: block;
11
+ border-bottom: 4px solid #CCC;
12
+ -moz-box-shadow: #666 2px 2px 15px;
13
+ -webkit-box-shadow: #666 2px 2px 15px;
14
+ box-shadow: #666 2px 2px 15px;
15
+ display:none;
16
+ overflow: auto;
17
+ }
18
+ #fixed-gallery button{
19
+ position: fixed;
20
+ right: 35px;
21
+ z-index: 200001;
22
+ }
23
+
24
+ %div{:id=>"fixed-gallery"}
25
+ - resource_class.lolita.tabs.select{|tab| tab.type == :files}.each do |tab|
26
+ %h1= tab.title
27
+ - files = tab.association_type == :one ? [resource.send(tab.association.name)].compact : resource.send(tab.association.name)
28
+ - files.each do |file|
29
+ - if file.send(tab.uploader).to_s =~ /(jpg|jpeg|png|gif)$/i
30
+ = image_tag(file.send(tab.uploader).url)
31
+ - else
32
+ = link_to file.send(tab.uploader).url, file.send(tab.uploader).url
33
+ %button{:onclick=>"$('#fixed-gallery').hide();"}Aizvērt
@@ -1,3 +1,7 @@
1
- <%= form_tag send(:"lolita_upload_#{tab.type.to_s.singularize}_path",:id=>file.id),:method=>:put,:remote=>true,:id=>"edit_#{tab.type}_#{file.id}" do %>
2
- <%= text_field_tag "file[name]",file.name %>
3
- <% end %>
1
+ <%= form_tag send(:"lolita_#{resource_class.model_name.singular}_upload_path", "#{resource_class.model_name.singular}_id" => resource.id, :association => tab.association.name, :id=>file.id),:method=>:put,:remote=>true,:id=>"edit_#{tab.association.name}_#{file.id}" do %>
2
+ <% tab.editable_fields.each do |name| %>
3
+ <%= label_tag "file[#{name}]", file.class.human_attribute_name(name) %>
4
+ <%= text_field_tag "file[#{name}]",file.send(name) %>
5
+ <br />
6
+ <% end %>
7
+ <% end %>
@@ -1,14 +1,14 @@
1
- <table id="file_list_for_<%=tab.type%>" >
2
- <thead>
3
- <tr>
4
- <th>Name</th>
5
- <th>*</th>
6
- </tr>
7
- </thead>
8
- <tbody>
9
- <% files = tab.association_type == :one ? [resource.send(tab.association.name)].compact : resource.send(tab.association.name)%>
10
- <% files.each do |file| %>
11
- <%= render_component *tab.build("",:row,:file=>file,:value=>nil) %>
12
- <% end %>
13
- </tbody>
1
+ <table id="file_list_for_<%=tab.association.name%>">
2
+ <thead>
3
+ <tr>
4
+ <th>Name</th>
5
+ <th>*</th>
6
+ </tr>
7
+ </thead>
8
+ <tbody>
9
+ <% files = tab.association_type == :one ? [resource.send(tab.association.name)].compact : resource.send(tab.association.name) %>
10
+ <% files.each do |file| %>
11
+ <%= render_component *tab.build("",:row,:file=>file,:value=>nil) %>
12
+ <% end %>
13
+ </tbody>
14
14
  </table>
@@ -1,6 +1,6 @@
1
- <td>
2
- <%=render_component *tab.build("",:form,:file=>file)%>
3
- </td>
4
- <td>
5
- <%= link_to "S", "#", :onclick=>"$('##{"edit_#{tab.type}_#{file.id}"}').submit();return false;" %>
1
+ <td>
2
+ <%=render_component *tab.build("",:form,:file=>file)%>
3
+ </td>
4
+ <td>
5
+ <%= link_to "S", "#", :onclick=>"$('#edit_#{tab.association.name}_#{file.id}').submit();return false;" %>
6
6
  </td>
@@ -1,3 +1,6 @@
1
- <tr id="upload_<%=tab.type%>_row_<%=file.id%>" data-<%=tab.type%>-id="<%=file.id%>" >
2
- <%= render_component *tab.build("",:cells,:file=>file) %>
1
+ <tr id="upload_<%=tab.association.name%>_row_<%=file.id%>" data-<%=tab.association.name%>-id="<%=file.id%>">
2
+ <%= render_component *tab.build("",:cells,:file=>file) %>
3
+ <script>
4
+ $('#fixed-gallery').append("<%=escape_javascript(render_component(*tab.build("",:file,:file=>file,:format=>"html")))%>");
5
+ </script>
3
6
  </tr>
@@ -1 +1 @@
1
- $("#upload_<%=tab.type%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(*tab.build("",:cells,:file=>file,:format=>"html")))%>")
1
+ $("#upload_<%=tab.association.name%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(*tab.build("",:cells,:file=>file,:format=>"html")))%>")
@@ -1,77 +1,79 @@
1
-
2
- <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/overcast/jquery-ui.css" type="text/css" />
3
- <link rel="stylesheet" href="/stylesheets/lolita/upload/jquery.ui.plupload.css" type="text/css" />
4
-
5
- <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
6
- <script type="text/javascript" src="/javascripts/lolita/upload/plupload.full.js"></script>
7
- <script type="text/javascript" src="/javascripts/lolita/upload/jquery.ui.plupload.js"></script>
8
- <% unless Lolita.locale.to_s.downcase=="en" %>
9
- <script type="text/javascript" src="/javascripts/lolita/upload/I18n/<%=Lolita.locale%>.js"></script>
10
- <% end %>
11
- <script type="text/javascript">
12
- $(function(){
13
- $("#<%=container%>").plupload({
14
- // General settings
15
- runtimes : 'html5,flash',
16
- url : '<%=send(:"lolita_upload_#{tab.type}_path")%>',
17
- max_file_size : '10mb',
18
- chunk_size : '1mb',
19
- unique_names : true,
20
- rename: true,
21
- <% if tab.extensions.any? %>
22
- filters:[
23
- <% tab.extensions.each do |ext_data| %>
24
- {title: "<%=ext_data[:title]%>", extensions: "<%= ext_data[:extensions].is_a?(Array) ? ext_data[:extensions].join(",") : ext_data[:extensions] %>"},
25
- <% end %>
26
- ],
27
- <% end %>
28
- multipart: true,
29
- multipart_params: {
30
- "authenticity_token" : '<%= form_authenticity_token %>',
31
- "<%="upload[#{tab.association.options[:as]}_type]"%>": "<%=resource.class%>",
32
- "<%="upload[#{tab.association.options[:as]}_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>"
33
- },
34
- headers:{
35
- "X-CSRF-Token": $("meta[name='csrf-token']").attr("content")
36
- },
37
-
38
- // Flash settings
39
- flash_swf_url : '/javascripts/lolita/upload/plupload.flash.swf',
40
- init:{
41
- FileUploaded:function(uploader, file, info){
42
- <% if tab.association_type == :one %>
43
- uploader.splice(0,10);
44
- $("#file_list_for_<%=tab.type%>>tbody").html("")
45
- $("#file_list_for_<%=tab.type%>>tbody").append(info.response)
46
- <% else %>
47
- $("#file_list_for_<%=tab.type%>>tbody").append(info.response)
48
- <% end %>
49
-
50
- <% if tab.association_type == :many %>
51
- var ids="<%="#{resource_name}[#{tab.association.name}_ids][]"%>"
52
- <% else %>
53
- var ids = "<%="#{resource_name}[#{tab.association.name}_new]"%>"
54
- <% end %>
55
-
56
- var existing_ids=[]
57
- $("input.<%=tab.type%>-ids").each(function(){
58
- existing_ids.push($(this).val())
59
- })
60
-
61
- var new_ids=[]
62
- $("#file_list_for_<%=tab.type%> tr[data-<%=tab.type%>-id]").each(function(){
63
- if($.inArray($(this).attr("data-<%=tab.type%>-id"),existing_ids)<0){
64
- new_ids.push($(this).attr("data-<%=tab.type%>-id"))
65
- }
66
- })
67
- for(var i in new_ids){
68
- $("#<%=tab.type%>_form").append('<input type="hidden" class="<%=tab.type%>-ids" name="'+ids+'" value="'+new_ids[i]+'" />')
69
- }
70
-
71
- }
72
- },
73
-
74
- });
75
-
76
- });
77
- </script>
1
+ <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/overcast/jquery-ui.css" type="text/css" />
2
+ <link rel="stylesheet" href="/stylesheets/lolita/upload/jquery.ui.plupload.css" type="text/css" />
3
+
4
+ <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
5
+ <script type="text/javascript" src="/javascripts/lolita/upload/plupload.full.js"></script>
6
+ <script type="text/javascript" src="/javascripts/lolita/upload/jquery.ui.plupload.js"></script>
7
+ <% unless Lolita.locale.to_s.downcase=="en" %>
8
+ <script type="text/javascript" src="/javascripts/lolita/upload/I18n/<%=Lolita.locale%>.js"></script>
9
+ <% end %>
10
+ <script type="text/javascript">
11
+ $(function(){
12
+ $("#<%=container%>").plupload({
13
+ // General settings
14
+ runtimes : 'html5,flash',
15
+ url : '<%=send(:"create_upload_lolita_#{tab.dbi.klass.model_name.plural.downcase}_path", :association => tab.association.name)%>',
16
+ max_file_size : '100mb',
17
+ unique_names : true,
18
+ rename: true,
19
+ <% if tab.filters.any? %>
20
+ filters:[
21
+ <% tab.filters.each do |fdata| %>
22
+ {title: "<%=fdata[:title]%>", extensions: "<%= fdata[:extensions].is_a?(Array) ? fdata[:extensions].join(",") : fdata[:extensions] %>"},
23
+ <% end %>
24
+ ],
25
+ <% end %>
26
+ multipart: true,
27
+ multipart_params: {
28
+ "authenticity_token" : '<%= form_authenticity_token %>',
29
+ <% if tab.association.options[:as] -%>
30
+ "<%="upload[#{tab.association.options[:as]}_type]"%>": "<%=resource.class%>",
31
+ "<%="upload[#{tab.association.options[:as]}_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>"
32
+ <% else -%>
33
+ "<%="upload[#{lolita_mapping.singular}_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>"
34
+ <% end -%>
35
+ },
36
+ headers:{
37
+ "X-CSRF-Token": $("meta[name='csrf-token']").attr("content")
38
+ },
39
+
40
+ // Flash settings
41
+ flash_swf_url : '/javascripts/lolita/upload/plupload.flash.swf',
42
+ init:{
43
+ FileUploaded:function(uploader, file, info){
44
+ <% if tab.association_type == :many %>
45
+ $("#file_list_for_<%=tab.association.name%>>tbody").append(info.response)
46
+ <% else %>
47
+ uploader.splice(0,10);
48
+ $("#file_list_for_<%=tab.association.name%>>tbody").html("")
49
+ $("#file_list_for_<%=tab.association.name%>>tbody").append(info.response)
50
+ <% end %>
51
+
52
+ <% if tab.association_type == :many %>
53
+ var ids="<%="#{resource_name}[#{tab.association.name.to_s.singularize}_ids][]"%>"
54
+ <% else %>
55
+ var ids = "<%="#{resource_name}[#{tab.association.name.to_s.singularize}_new]"%>"
56
+ <% end %>
57
+
58
+ var existing_ids=[]
59
+ $("input.<%=tab.association.name%>-ids").each(function(){
60
+ existing_ids.push($(this).val())
61
+ })
62
+
63
+ var new_ids=[]
64
+ $("#file_list_for_<%=tab.association.name%> tr[data-<%=tab.association.name%>-id]").each(function(){
65
+ if($.inArray($(this).attr("data-<%=tab.association.name%>-id"),existing_ids)<0){
66
+ new_ids.push($(this).attr("data-<%=tab.association.name%>-id"))
67
+ }
68
+ })
69
+ for(var i in new_ids){
70
+ $("#<%=tab.association.name%>_form").append('<input type="hidden" class="<%=tab.association.name%>-ids" name="'+ids+'" value="'+new_ids[i]+'" />')
71
+ }
72
+
73
+ }
74
+ },
75
+
76
+ });
77
+
78
+ });
79
+ </script>
@@ -1,19 +1,19 @@
1
- en:
2
- lolita:
3
- upload:
4
- errors:
5
- "file too big": "file too big (max %{value} %{unit})"
6
- support:
7
- bytes:
8
- byte:
9
- one: byte
10
- other: bytes
11
- kilobyte:
12
- one: kilobyte
13
- other: kilobytes
14
- megabyte:
15
- one: megabyte
16
- other: megabytes
17
- gigabyte:
18
- one: gigabyte
1
+ en:
2
+ lolita:
3
+ upload:
4
+ errors:
5
+ "file too big": "file too big (max %{value} %{unit})"
6
+ support:
7
+ bytes:
8
+ byte:
9
+ one: byte
10
+ other: bytes
11
+ kilobyte:
12
+ one: kilobyte
13
+ other: kilobytes
14
+ megabyte:
15
+ one: megabyte
16
+ other: megabytes
17
+ gigabyte:
18
+ one: gigabyte
19
19
  other: gigabytes
@@ -1,26 +1,26 @@
1
- Feature: lolita have new configuration for tab
2
-
3
- Lolita file upload define new configuration for lolita tabs, that
4
- allow to specify file types, file list view and add atributes for file.
5
- Tab type for lolita-file-upload will be :file
6
-
7
- Scenario: i am able to define new tab with type :file and set allowed file types
8
- Given a lolita and lolita-file-upload
9
- When I define a file tab for post
10
- Then I can set included extension type pdf
11
-
12
- Scenario: set maximum file upload size
13
- Given a lolita
14
- And a rails
15
- And rails application
16
- And file tab for post
17
- When I set maximum file upload size to 100000
18
- Then I cannot upload file large_file.txt
19
-
20
- Scenario: set assciation with Lolita::Upload::File
21
- Given a lolita
22
- And lolita-file-upload
23
- When I define a file tab for post
24
- Then Post has association with Lolita::Upload::File
25
- And association name for Post is :files
1
+ Feature: lolita have new configuration for tab
2
+
3
+ Lolita file upload define new configuration for lolita tabs, that
4
+ allow to specify file types, file list view and add atributes for file.
5
+ Tab type for lolita-file-upload will be :file
6
+
7
+ Scenario: i am able to define new tab with type :file and set allowed file types
8
+ Given a lolita and lolita-file-upload
9
+ When I define a file tab for post
10
+ Then I can set included extension type pdf
11
+
12
+ Scenario: set maximum file upload size
13
+ Given a lolita
14
+ And a rails
15
+ And rails application
16
+ And file tab for post
17
+ When I set maximum file upload size to 100000
18
+ Then I cannot upload file large_file.txt
19
+
20
+ Scenario: set assciation with Lolita::Upload::File
21
+ Given a lolita
22
+ And lolita-file-upload
23
+ When I define a file tab for post
24
+ Then Post has association with Lolita::Upload::File
25
+ And association name for Post is :files
26
26
 
@@ -1,14 +1,14 @@
1
- Feature: lolita-file-upload connects to Lolita
2
-
3
- To have all file upload features, file upload gem should connect itsefl to lolita base.
4
-
5
- Scenario: lolita-file-upload load in universe
6
- Given a lolita
7
- When I load lolita-file-upload
8
- Then lolita should have file-upload module
9
-
10
- Scenario: lolita-file-upload starts rails engine
11
- Given a rails
12
- When I load lolita-file-upload
13
- Then I have LolitaFileUpload engine
14
-
1
+ Feature: lolita-file-upload connects to Lolita
2
+
3
+ To have all file upload features, file upload gem should connect itsefl to lolita base.
4
+
5
+ Scenario: lolita-file-upload load in universe
6
+ Given a lolita
7
+ When I load lolita-file-upload
8
+ Then lolita should have file-upload module
9
+
10
+ Scenario: lolita-file-upload starts rails engine
11
+ Given a rails
12
+ When I load lolita-file-upload
13
+ Then I have LolitaFileUpload engine
14
+
@@ -1,17 +1,17 @@
1
- Feature: all resoures have new routes for file upload
2
-
3
- File upload lives in lolita/upload and loads only once when any of lolita resources has defined files tab.
4
-
5
- Scenario: extend resources path
6
- Given a lolita
7
- And a rails
8
- And rails application
9
- And lolita-file-upload
10
- When I load routes
11
- Then I have get route /lolita/upload/files/new
12
- And I have get route /lolita/upload/files/1/edit
13
- And I have get route /lolita/upload/files/1
14
- And I have post route /lolita/upload/files
15
- And I have put route /lolita/upload/files/1
16
- And I have delete route /lolita/upload/files/1
1
+ Feature: all resoures have new routes for file upload
2
+
3
+ File upload lives in lolita/upload and loads only once when any of lolita resources has defined files tab.
4
+
5
+ Scenario: extend resources path
6
+ Given a lolita
7
+ And a rails
8
+ And rails application
9
+ And lolita-file-upload
10
+ When I load routes
11
+ Then I have get route /lolita/upload/files/new
12
+ And I have get route /lolita/upload/files/1/edit
13
+ And I have get route /lolita/upload/files/1
14
+ And I have post route /lolita/upload/files
15
+ And I have put route /lolita/upload/files/1
16
+ And I have delete route /lolita/upload/files/1
17
17
  And I have get route /lolita/upload/files
@@ -1,112 +1,112 @@
1
- Given /^a lolita$/ do
2
-
3
- end
4
-
5
- When /^I load lolita\-file\-upload$/ do
6
- require "lolita-file-upload"
7
- end
8
-
9
- Then /^lolita should have file\-upload module$/ do
10
- Lolita.modules.include?(Lolita::FileUpload).should be_true
11
- end
12
-
13
- Given /^a rails$/ do
14
- require 'rails'
15
- require 'lolita/rails/all'
16
- require 'lolita-file-upload/rails'
17
- end
18
-
19
- Given /^rails application$/ do
20
- require File.expand_path("test_orm/rails/config/enviroment")
21
- end
22
-
23
- Then /^I have LolitaFileUpload engine$/ do
24
- defined?(LolitaFileUpload::Engine).should be_true
25
- end
26
-
27
- Given /^a lolita and lolita\-file\-upload$/ do
28
-
29
- end
30
-
31
- When /^I define a file tab for (\w+)$/ do |model_name|
32
- @file_tab=Support.file_tab(model_name)
33
- end
34
-
35
- Then /^I can set included extension type (\w+)$/ do |ext_name|
36
- @file_tab.extension(ext_name)
37
- @file_tab.extensions.size.should == 1
38
- end
39
-
40
- Given /^lolita\-file\-upload$/ do
41
-
42
- end
43
-
44
- Given /^file tab for (\w+)$/ do |model_name|
45
- @file_tab=Support.file_tab(model_name)
46
- end
47
-
48
- When /^I set maximum file upload size to (\d+)$/ do |size|
49
- @file_tab.maxfilesize(size)
50
- end
51
-
52
- Then /^I (c\w+)\supload file (\w+\.\w+)$/ do |predicate,file_name|
53
- file=Lolita::Upload::File.create(:asset=>Support.get_file(file_name))
54
- if predicate=="can"
55
- file.errors.should be_empty
56
- elsif predicate=="cannot"
57
- file.errors[:asset].should_not be_nil
58
- end
59
- end
60
-
61
- Then /^(\w+)\s+has association with ([\w:]+)$/ do |model_name,klass|
62
- model=Support.get_model(model_name)
63
- model.lolita.dbi.associations_klass_names.should include(klass)
64
- end
65
-
66
- Then /^association name for (\w+)\sis :(\w+)$/ do |model_name,assoc_name|
67
- model=Support.get_model(model_name)
68
- model.lolita.dbi.reflect_on_association(assoc_name.to_sym).should_not be_nil
69
- end
70
-
71
- When /^I upload file (.+)$/ do |file_name|
72
- pending # express the regexp above with the code you wish you had
73
- end
74
-
75
- Then /^I see (\w+)$/ do |file_name|
76
- pending # express the regexp above with the code you wish you had
77
- end
78
-
79
- Then /^I change file attribute ([^\s]) to (\w+)$/ do |attribute,value|
80
- pending # express the regexp above with the code you wish you had
81
- end
82
-
83
- Then /^save file$/ do
84
- pending # express the regexp above with the code you wish you had
85
- end
86
-
87
- Then /^I see (\w+)$/ do |file_name|
88
- pending # express the regexp above with the code you wish you had
89
- end
90
-
91
- When /^I load routes$/ do
92
- # routes is loaded when rails application loads, but i will load matcher for that
93
- self.extend(Lolita::Test::Matchers)
94
- # RSpec::Matchers.send(:include,Lolita::Test::Matchers)
95
- end
96
-
97
- Then /^I have (get|post|delete|put) route (.+)$/ do |method,url|
98
- {method=>url}.should be_routable
99
- end
100
-
101
- Given /^byte converter$/ do
102
- @converter=Lolita::Support::Bytes
103
- end
104
-
105
- When /^I humanize "([^"]*)"$/ do |size|
106
- @converter=@converter.new(eval(size))
107
- end
108
-
109
- Then /^I should get "([^"]*)" and "([^"]*)"$/ do |unit, limit|
110
- @converter.unit.should == unit
111
- @converter.value.should == limit.to_f
112
- end
1
+ Given /^a lolita$/ do
2
+
3
+ end
4
+
5
+ When /^I load lolita\-file\-upload$/ do
6
+ require "lolita-file-upload"
7
+ end
8
+
9
+ Then /^lolita should have file\-upload module$/ do
10
+ Lolita.modules.include?(Lolita::FileUpload).should be_true
11
+ end
12
+
13
+ Given /^a rails$/ do
14
+ require 'rails'
15
+ require 'lolita/rails/all'
16
+ require 'lolita-file-upload/rails'
17
+ end
18
+
19
+ Given /^rails application$/ do
20
+ require File.expand_path("test_orm/rails/config/enviroment")
21
+ end
22
+
23
+ Then /^I have LolitaFileUpload engine$/ do
24
+ defined?(LolitaFileUpload::Engine).should be_true
25
+ end
26
+
27
+ Given /^a lolita and lolita\-file\-upload$/ do
28
+
29
+ end
30
+
31
+ When /^I define a file tab for (\w+)$/ do |model_name|
32
+ @file_tab=Support.file_tab(model_name)
33
+ end
34
+
35
+ Then /^I can set included extension type (\w+)$/ do |ext_name|
36
+ @file_tab.extension(ext_name)
37
+ @file_tab.extensions.size.should == 1
38
+ end
39
+
40
+ Given /^lolita\-file\-upload$/ do
41
+
42
+ end
43
+
44
+ Given /^file tab for (\w+)$/ do |model_name|
45
+ @file_tab=Support.file_tab(model_name)
46
+ end
47
+
48
+ When /^I set maximum file upload size to (\d+)$/ do |size|
49
+ @file_tab.maxfilesize(size)
50
+ end
51
+
52
+ Then /^I (c\w+)\supload file (\w+\.\w+)$/ do |predicate,file_name|
53
+ file=Lolita::Upload::File.create(:asset=>Support.get_file(file_name))
54
+ if predicate=="can"
55
+ file.errors.should be_empty
56
+ elsif predicate=="cannot"
57
+ file.errors[:asset].should_not be_nil
58
+ end
59
+ end
60
+
61
+ Then /^(\w+)\s+has association with ([\w:]+)$/ do |model_name,klass|
62
+ model=Support.get_model(model_name)
63
+ model.lolita.dbi.associations_klass_names.should include(klass)
64
+ end
65
+
66
+ Then /^association name for (\w+)\sis :(\w+)$/ do |model_name,assoc_name|
67
+ model=Support.get_model(model_name)
68
+ model.lolita.dbi.reflect_on_association(assoc_name.to_sym).should_not be_nil
69
+ end
70
+
71
+ When /^I upload file (.+)$/ do |file_name|
72
+ pending # express the regexp above with the code you wish you had
73
+ end
74
+
75
+ Then /^I see (\w+)$/ do |file_name|
76
+ pending # express the regexp above with the code you wish you had
77
+ end
78
+
79
+ Then /^I change file attribute ([^\s]) to (\w+)$/ do |attribute,value|
80
+ pending # express the regexp above with the code you wish you had
81
+ end
82
+
83
+ Then /^save file$/ do
84
+ pending # express the regexp above with the code you wish you had
85
+ end
86
+
87
+ Then /^I see (\w+)$/ do |file_name|
88
+ pending # express the regexp above with the code you wish you had
89
+ end
90
+
91
+ When /^I load routes$/ do
92
+ # routes is loaded when rails application loads, but i will load matcher for that
93
+ self.extend(Lolita::Test::Matchers)
94
+ # RSpec::Matchers.send(:include,Lolita::Test::Matchers)
95
+ end
96
+
97
+ Then /^I have (get|post|delete|put) route (.+)$/ do |method,url|
98
+ {method=>url}.should be_routable
99
+ end
100
+
101
+ Given /^byte converter$/ do
102
+ @converter=Lolita::Support::Bytes
103
+ end
104
+
105
+ When /^I humanize "([^"]*)"$/ do |size|
106
+ @converter=@converter.new(eval(size))
107
+ end
108
+
109
+ Then /^I should get "([^"]*)" and "([^"]*)"$/ do |unit, limit|
110
+ @converter.unit.should == unit
111
+ @converter.value.should == limit.to_f
112
+ end