lolita-file-upload 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.document +5 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +25 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +39 -0
  7. data/VERSION +1 -0
  8. data/app/controllers/lolita/upload/files_controller.rb +51 -0
  9. data/app/models/lolita/upload/file.rb +34 -0
  10. data/app/uploaders/file_uploader.rb +12 -0
  11. data/app/views/components/lolita/tab/_files.html.erb +13 -0
  12. data/app/views/components/lolita/tab/files/_cells.html.erb +5 -0
  13. data/app/views/components/lolita/tab/files/_destroy.js.erb +2 -0
  14. data/app/views/components/lolita/tab/files/_edit.js.erb +1 -0
  15. data/app/views/components/lolita/tab/files/_form.html.erb +3 -0
  16. data/app/views/components/lolita/tab/files/_list.html.erb +13 -0
  17. data/app/views/components/lolita/tab/files/_list_form.html.erb +6 -0
  18. data/app/views/components/lolita/tab/files/_row.html.erb +3 -0
  19. data/app/views/components/lolita/tab/files/_update.js.erb +1 -0
  20. data/app/views/components/lolita/tab/files/_upload_script.html.erb +60 -0
  21. data/config/locales/en.yml +19 -0
  22. data/features/configuration_for_tab.feature +26 -0
  23. data/features/connect_with_lolita.feature +14 -0
  24. data/features/extend_resources_with_new_routes.feature +17 -0
  25. data/features/step_definitions/lolita_steps.rb +112 -0
  26. data/features/support/env.rb +15 -0
  27. data/features/support_byte_converter.feature +31 -0
  28. data/features/upload_file.feature +16 -0
  29. data/lib/generators/lolita_file_upload/assets_generator.rb +12 -0
  30. data/lib/generators/lolita_file_upload/install_generator.rb +19 -0
  31. data/lib/generators/lolita_file_upload/templates/migration.rb +25 -0
  32. data/lib/lolita-file-upload/configuration/tab/files.rb +53 -0
  33. data/lib/lolita-file-upload/module.rb +6 -0
  34. data/lib/lolita-file-upload/rails/file_upload_routes.rb +20 -0
  35. data/lib/lolita-file-upload/rails.rb +8 -0
  36. data/lib/lolita-file-upload.rb +28 -0
  37. data/lib/support/bytes.rb +59 -0
  38. data/log/development.log +0 -0
  39. data/lolita-file-upload.gemspec +135 -0
  40. data/public/images/lolita/upload/plupload/backgrounds.gif +0 -0
  41. data/public/images/lolita/upload/plupload/buttons-disabled.png +0 -0
  42. data/public/images/lolita/upload/plupload/buttons.png +0 -0
  43. data/public/images/lolita/upload/plupload/delete.gif +0 -0
  44. data/public/images/lolita/upload/plupload/done.gif +0 -0
  45. data/public/images/lolita/upload/plupload/error.gif +0 -0
  46. data/public/images/lolita/upload/plupload/plupload-bw.png +0 -0
  47. data/public/images/lolita/upload/plupload/plupload.png +0 -0
  48. data/public/images/lolita/upload/plupload/throbber.gif +0 -0
  49. data/public/images/lolita/upload/plupload/transp50.png +0 -0
  50. data/public/javascripts/lolita/upload/I18n/ru.js +22 -0
  51. data/public/javascripts/lolita/upload/jquery.plupload.queue.min.js +1 -0
  52. data/public/javascripts/lolita/upload/jquery.ui.plupload.min.js +1 -0
  53. data/public/javascripts/lolita/upload/plupload.flash.swf +0 -0
  54. data/public/javascripts/lolita/upload/plupload.full.min.js +2 -0
  55. data/public/javascripts/lolita/upload/plupload.silverlight.xap +0 -0
  56. data/public/stylesheets/lolita/upload/jquery.ui.plupload.css +139 -0
  57. data/public/stylesheets/lolita/upload/plupload.queue.css +177 -0
  58. data/spec/configuration/tab/files_spec.rb +37 -0
  59. data/spec/lolita/support/bytes_spec.rb +36 -0
  60. data/spec/models/file_spec.rb +34 -0
  61. data/spec/spec_helper.rb +29 -0
  62. data/spec/support/post.rb +3 -0
  63. data/spec/uploaders/file_uploader_spec.rb +12 -0
  64. data/test_orm/active_record/post.rb +13 -0
  65. data/test_orm/active_record.rb +9 -0
  66. data/test_orm/config/active_record.yml +2 -0
  67. data/test_orm/coverage.rb +19 -0
  68. data/test_orm/db/migrate/01_create_posts.rb +15 -0
  69. data/test_orm/db/migrate/02_create_files.rb +17 -0
  70. data/test_orm/files/large_file.txt +201 -0
  71. data/test_orm/files/normal_file.txt +2 -0
  72. data/test_orm/rails/config/application.rb +8 -0
  73. data/test_orm/rails/config/enviroment.rb +5 -0
  74. data/test_orm/rails/config/routes.rb +3 -0
  75. data/test_orm/rails/log/development.log +0 -0
  76. data/test_orm/support.rb +27 -0
  77. metadata +195 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format d
data/Gemfile ADDED
@@ -0,0 +1,25 @@
1
+ source "http://rubygems.org"
2
+
3
+ #gem "lolita"
4
+ gem "carrierwave", "~> 0.5.2"
5
+ group :test do
6
+ gem "rspec-rails", "~> 2.5"
7
+ gem "ffaker"
8
+ gem "factory_girl"
9
+ gem "sqlite3"
10
+ end
11
+
12
+ group :development do
13
+ gem "cucumber", "~> 0.10"
14
+ gem "cucumber-rails", "~> 0.3.2"
15
+ gem "bundler", "~> 1.0"
16
+ gem "jeweler", "~> 1.5"
17
+ end
18
+
19
+ group :test do
20
+ gem "rspec", "~> 2.5"
21
+ gem 'cover_me', '>= 1.0.0.rc6'
22
+ gem 'activerecord', "~> 3.0", :require=>false
23
+ end
24
+
25
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Arturs Meisters
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = lolita-file-upload
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to lolita-file-upload
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Arturs Meisters. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "lolita-file-upload"
16
+ gem.homepage = "http://github.com/ithouse/lolita-file-upload"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{File upload gem for Lolita CMS}
19
+ gem.description = %Q{File upload gem for Lolita with with fulll integration - models, controller, views}
20
+ gem.email = "support@ithouse.lv"
21
+ gem.authors = ["ITHouse","Arturs Meisters"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ task :default => :test
30
+
31
+ require 'rake/rdoctask'
32
+ Rake::RDocTask.new do |rdoc|
33
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
34
+
35
+ rdoc.rdoc_dir = 'rdoc'
36
+ rdoc.title = "lolita-file-upload #{version}"
37
+ rdoc.rdoc_files.include('README*')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
39
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,51 @@
1
+ module Lolita
2
+ module Upload
3
+ class FilesController < ApplicationController
4
+ include Lolita::Controllers::UserHelpers
5
+ include Lolita::Controllers::InternalHelpers
6
+ before_filter :authenticate_lolita_user!
7
+ before_filter :build_file, :only=>[:create]
8
+ before_filter :set_file, :only=>[:edit,:update,:destroy]
9
+ before_filter :set_tab, :only=>[:edit,:update,:destroy,:create]
10
+
11
+ respond_to :js,:html
12
+
13
+ def create
14
+ @file.asset = params[:file]
15
+ @file.save!
16
+ render_component :"lolita/tab/files",:row,:file=>@file, :tab=>@tab
17
+ end
18
+
19
+ def edit
20
+ render_component :"lolita/tab/files", :edit, :file=>@file,:tab=>@tab
21
+ end
22
+
23
+ def update
24
+ @file.update_attributes!(params[:file])
25
+ render_component :"lolita/tab/files", :update, :file=>@file,:tab=>@tab
26
+ end
27
+
28
+
29
+ def destroy
30
+ @file.destroy
31
+ render_component :"lolita/tab/files",:destroy,:file=>@file,:tab=>@tab
32
+ end
33
+
34
+ private
35
+
36
+ def build_file
37
+ @file = Lolita::Upload::File.new(params[:upload])
38
+ end
39
+
40
+ def set_file
41
+ dbi=Lolita::DBI::Base.new(Lolita::Upload::File)
42
+ @file=dbi.find_by_id(params[:id]) || build_file
43
+ end
44
+
45
+ def set_tab
46
+ fileable_class=@file.fileable_type.constantize
47
+ @tab=fileable_class.lolita.tabs.by_type(:files)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,34 @@
1
+ module Lolita
2
+ module Upload
3
+ class File < ActiveRecord::Base
4
+ set_table_name :lolita_files
5
+
6
+ mount_uploader :asset, FileUploader
7
+ belongs_to :fileable, :polymorphic=>true
8
+
9
+ validate :size_limit
10
+ before_save :set_metadata
11
+
12
+
13
+ private
14
+
15
+ def size_limit
16
+ if self.fileable && lolita=self.fileable.class.lolita
17
+ maxsize=lolita.tabs.by_type(:files).maxfilesize
18
+ if maxsize.to_i>0 && self.asset.file.size>maxsize
19
+ bytes=Lolita::Support::Bytes.new(maxsize)
20
+ self.errors.add(:asset,I18n.t("lolita.upload.errors.file too big",:value=>bytes.value,:unit=>bytes.unit))
21
+ end
22
+ end
23
+ end
24
+
25
+ def set_metadata
26
+ self.name||=::File.basename(self.asset.to_s)
27
+ self.asset_size=self.asset.file.size
28
+ self.asset_extension=::File.extname(self.asset.to_s).gsub(".","")
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,12 @@
1
+ class FileUploader < CarrierWave::Uploader::Base
2
+ storage :file
3
+ def timestamp
4
+ (model.created_at || Time.now).strftime("%Y%m")
5
+ end
6
+
7
+ # With slash in first place it will be absolute url, otherwise relative to Rails.root+"/public"
8
+ def store_dir
9
+ "uploads/#{model.class.to_s.underscore}/#{timestamp}/#{model.id}"
10
+ end
11
+
12
+ end
@@ -0,0 +1,13 @@
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 :"lolita/tab/files", :list,:tab=>tab %>
8
+ </div>
9
+ <%= render_component :"lolita/tab/files", :upload_script,
10
+ :container=>"file_upload_container",:tab=>tab
11
+ %>
12
+ <%= render_component :"lolita/tab", :fields, :tab=>tab %>
13
+
@@ -0,0 +1,5 @@
1
+ <td><%=file.name || "-"%></td>
2
+ <td>
3
+ <%=link_to "E",send(:"edit_lolita_upload_#{tab.type.to_s.singularize}_path",:id=>file.id),:remote=>true %>
4
+ <%= link_to "D",send(:"lolita_upload_#{tab.type.to_s.singularize}_path",:id=>file.id),:method=>:delete,:remote=>true,:confirm=>"Are you sure?" %>
5
+ </td>
@@ -0,0 +1,2 @@
1
+ $("#upload_<%=tab.type%>_row_<%=file.id%>").remove()
2
+ $("input.<%=tab.type%>-ids[value=<%=file.id%>]").remove()
@@ -0,0 +1 @@
1
+ $("#upload_<%=tab.type%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(:"lolita/tab/files",:list_form,:tab=>tab,:file=>file,:format=>"html"))%>")
@@ -0,0 +1,3 @@
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 %>
@@ -0,0 +1,13 @@
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
+ <% resource.send(tab.association.name).each do |file| %>
10
+ <%= render_component :"lolita/tab/files", :row, :file=>file,:tab=>tab,:value=>nil %>
11
+ <% end %>
12
+ </tbody>
13
+ </table>
@@ -0,0 +1,6 @@
1
+ <td>
2
+ <%=render_component :"lolita/tab/files", :form, :tab=>tab,:file=>file%>
3
+ </td>
4
+ <td>
5
+ <%= link_to "S", "#", :onclick=>"$('##{"edit_#{tab.type}_#{file.id}"}').submit();return false;" %>
6
+ </td>
@@ -0,0 +1,3 @@
1
+ <tr id="upload_<%=tab.type%>_row_<%=file.id%>" data-<%=tab.type%>-id="<%=file.id%>" >
2
+ <%= render_component :"lolita/tab/files", :cells, :tab=>tab, :file=>file %>
3
+ </tr>
@@ -0,0 +1 @@
1
+ $("#upload_<%=tab.type%>_row_<%=file.id%>").html("<%=escape_javascript(render_component(:"lolita/tab/files",:cells,:tab=>tab,:file=>file,:format=>"html"))%>")
@@ -0,0 +1,60 @@
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.min.js"></script>
7
+ <script type="text/javascript" src="/javascripts/lolita/upload/jquery.ui.plupload.min.js"></script>
8
+ <% unless I18n.locale.to_s.downcase=="en" %>
9
+ <script type="text/javascript" src="/javascripts/lolita/upload/I18n/<%=I18n.locale%>.js"></script>
10
+ <% end %>
11
+
12
+ <script type="text/javascript">
13
+ $(function(){
14
+ $("#<%=container%>").plupload({
15
+ // General settings
16
+ runtimes : 'html5,flash',
17
+ url : '<%=send(:"lolita_upload_#{tab.type}_path")%>',
18
+ max_file_size : '10mb',
19
+ chunk_size : '1mb',
20
+ unique_names : true,
21
+ rename: true,
22
+ multipart: true,
23
+ multipart_params: {
24
+ "authenticity_token" : '<%= form_authenticity_token %>',
25
+ "<%="upload[#{tab.association.name.to_s.singularize}able_type]"%>": "<%=resource.class%>",
26
+ "<%="upload[#{tab.association.name.to_s.singularize}able_id]"%>": "<%=resource.new_record? ? 0 : resource.id%>"
27
+ },
28
+ headers:{
29
+ "X-CSRF-Token": $("meta[name='csrf-token']").attr("content")
30
+ },
31
+
32
+ // Flash settings
33
+ flash_swf_url : '/javascripts/lolita/upload/plupload.flash.swf',
34
+ init:{
35
+ FileUploaded:function(uploader, file, info){
36
+ $("#file_list_for_<%=tab.type%>>tbody").append(info.response)
37
+
38
+ var ids="<%="#{resource_name}[#{tab.type.to_s.singularize}_ids][]"%>"
39
+ var existing_ids=[]
40
+ $("input.<%=tab.type%>-ids").each(function(){
41
+ existing_ids.push($(this).val())
42
+ })
43
+
44
+ var new_ids=[]
45
+ $("#file_list_for_<%=tab.type%> tr[data-<%=tab.type%>-id]").each(function(){
46
+ if($.inArray($(this).attr("data-<%=tab.type%>-id"),existing_ids)<0){
47
+ new_ids.push($(this).attr("data-<%=tab.type%>-id"))
48
+ }
49
+ })
50
+ for(var i in new_ids){
51
+ $("#<%=tab.type%>_form").append('<input type="hidden" class="<%=tab.type%>-ids" name="'+ids+'" value="'+new_ids[i]+'" />')
52
+ }
53
+
54
+ }
55
+ },
56
+
57
+ });
58
+
59
+ });
60
+ </script>
@@ -0,0 +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
19
+ other: gigabytes
@@ -0,0 +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
26
+
@@ -0,0 +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
+
@@ -0,0 +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
17
+ And I have get route /lolita/upload/files
@@ -0,0 +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