uploadable 0.0.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.
Files changed (72) hide show
  1. data/.gitignore +2 -0
  2. data/.todo +7 -0
  3. data/Gemfile +10 -0
  4. data/Gemfile.lock +108 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +0 -0
  7. data/Rakefile +12 -0
  8. data/lib/uploadable.rb +26 -0
  9. data/lib/uploadable/instance_methods.rb +5 -0
  10. data/lib/uploadable/processor.rb +34 -0
  11. data/lib/uploadable/railtie.rb +10 -0
  12. data/lib/uploadable/version.rb +3 -0
  13. data/spec/spec_helper.rb +28 -0
  14. data/spec/support/csv/album_fixture_1.csv +2 -0
  15. data/spec/support/sample_app/.gitignore +15 -0
  16. data/spec/support/sample_app/Gemfile +5 -0
  17. data/spec/support/sample_app/Gemfile.lock +87 -0
  18. data/spec/support/sample_app/README.rdoc +261 -0
  19. data/spec/support/sample_app/Rakefile +7 -0
  20. data/spec/support/sample_app/app/controllers/application_controller.rb +3 -0
  21. data/spec/support/sample_app/app/helpers/application_helper.rb +2 -0
  22. data/spec/support/sample_app/app/mailers/.gitkeep +0 -0
  23. data/spec/support/sample_app/app/models/.gitkeep +0 -0
  24. data/spec/support/sample_app/app/models/album.rb +6 -0
  25. data/spec/support/sample_app/app/models/track.rb +10 -0
  26. data/spec/support/sample_app/app/models/user.rb +3 -0
  27. data/spec/support/sample_app/config.ru +4 -0
  28. data/spec/support/sample_app/config/application.rb +62 -0
  29. data/spec/support/sample_app/config/boot.rb +6 -0
  30. data/spec/support/sample_app/config/database.yml +25 -0
  31. data/spec/support/sample_app/config/environment.rb +5 -0
  32. data/spec/support/sample_app/config/environments/development.rb +37 -0
  33. data/spec/support/sample_app/config/environments/production.rb +67 -0
  34. data/spec/support/sample_app/config/environments/test.rb +37 -0
  35. data/spec/support/sample_app/config/initializers/backtrace_silencers.rb +7 -0
  36. data/spec/support/sample_app/config/initializers/inflections.rb +15 -0
  37. data/spec/support/sample_app/config/initializers/mime_types.rb +5 -0
  38. data/spec/support/sample_app/config/initializers/secret_token.rb +7 -0
  39. data/spec/support/sample_app/config/initializers/session_store.rb +8 -0
  40. data/spec/support/sample_app/config/initializers/wrap_parameters.rb +14 -0
  41. data/spec/support/sample_app/config/locales/en.yml +5 -0
  42. data/spec/support/sample_app/config/routes.rb +58 -0
  43. data/spec/support/sample_app/db/migrate/20120624173544_create_albums.rb +10 -0
  44. data/spec/support/sample_app/db/migrate/20120624173638_create_tracks.rb +10 -0
  45. data/spec/support/sample_app/db/migrate/20120625055607_create_users.rb +10 -0
  46. data/spec/support/sample_app/db/migrate/20120630102016_add_column_top_rated_to_tracks.rb +5 -0
  47. data/spec/support/sample_app/db/schema.rb +38 -0
  48. data/spec/support/sample_app/db/seeds.rb +7 -0
  49. data/spec/support/sample_app/doc/README_FOR_APP +2 -0
  50. data/spec/support/sample_app/lib/assets/.gitkeep +0 -0
  51. data/spec/support/sample_app/lib/tasks/.gitkeep +0 -0
  52. data/spec/support/sample_app/log/.gitkeep +0 -0
  53. data/spec/support/sample_app/public/404.html +26 -0
  54. data/spec/support/sample_app/public/422.html +26 -0
  55. data/spec/support/sample_app/public/500.html +25 -0
  56. data/spec/support/sample_app/public/favicon.ico +0 -0
  57. data/spec/support/sample_app/public/index.html +241 -0
  58. data/spec/support/sample_app/public/robots.txt +5 -0
  59. data/spec/support/sample_app/script/rails +6 -0
  60. data/spec/support/sample_app/test/fixtures/.gitkeep +0 -0
  61. data/spec/support/sample_app/test/functional/.gitkeep +0 -0
  62. data/spec/support/sample_app/test/integration/.gitkeep +0 -0
  63. data/spec/support/sample_app/test/performance/browsing_test.rb +12 -0
  64. data/spec/support/sample_app/test/test_helper.rb +13 -0
  65. data/spec/support/sample_app/test/unit/.gitkeep +0 -0
  66. data/spec/support/sample_app/vendor/assets/javascripts/.gitkeep +0 -0
  67. data/spec/support/sample_app/vendor/assets/stylesheets/.gitkeep +0 -0
  68. data/spec/support/sample_app/vendor/plugins/.gitkeep +0 -0
  69. data/spec/uploadable/processor_spec.rb +35 -0
  70. data/spec/uploadable_spec.rb +36 -0
  71. data/uploadable.gemspec +20 -0
  72. metadata +134 -0
@@ -0,0 +1,13 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
+ #
8
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
+ # -- they do not yet inherit this setting
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Uploadable::Processor" do
4
+ it "should take manadatory and optional attributes while initializing" do
5
+ processor = Uploadable::Processor.new :mandatory_fields => [:required], :optional_fields => [:maybe], :model => TestModel
6
+ processor.mandatory.should == [:required]
7
+ processor.optional.should == [:maybe]
8
+ processor.model.should == TestModel
9
+ end
10
+
11
+ describe "transform_csv" do
12
+ it "should error or of headers not valid" do
13
+ processor = Uploadable::Processor.new :mandatory_fields => [:title], :optional_fields => [:artist]
14
+ lambda { processor.transform_csv "Artist\n\"John Denver\"" }.should raise_error("Mandatory header(s): title is missing")
15
+ end
16
+
17
+ it "should transform csv into array of hashes and reject extra columns" do
18
+ processor = Uploadable::Processor.new :mandatory_fields => [:artist], :optional_fields => [:title]
19
+ result = processor.transform_csv "Artist,Title,Extra\n\"John Denver\",\"All Aboard!\",1\n\"Usher\",\"Looking 4 Myself\",2"
20
+
21
+ result.should == [{:artist => "John Denver", :title => "All Aboard!"}, {:artist=>"Usher", :title=>"Looking 4 Myself"}]
22
+ end
23
+
24
+ it "should transform the column values for which transform method is present" do
25
+ processor = Uploadable::Processor.new :mandatory_fields => [:name], :optional_fields => [:top_rated], :model => Track
26
+ result = processor.transform_csv "Name,Top Rated\n\"Waiting For A Train\",Y\n\"People Get Ready\",N\n\"Lining Track\","
27
+
28
+ result.should == [{:name => "Waiting For A Train", :top_rated => true}, {:name => "People Get Ready", :top_rated => false},
29
+ {:name => "Lining Track", :top_rated => false}]
30
+ end
31
+ end
32
+ end
33
+
34
+ class TestModel
35
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Uploadable" do
4
+ describe "uploadable" do
5
+ it "all active record models should have access to uploadable methods" do
6
+ Album.methods.should include(:uploadable)
7
+ User.methods.should include(:uploadable)
8
+ Track.methods.should include(:uploadable)
9
+ end
10
+
11
+ it "should initialize a procesor if model is uploadable" do
12
+ Album.instance_variable_get(:@upload_processor).should_not be_nil
13
+ User.instance_variable_get(:@upload_processor).should be_nil
14
+
15
+ Album.instance_variable_get(:@upload_processor).model.should == Album
16
+ end
17
+
18
+ it "should defind upload_from_csv method for models" do
19
+ Album.should respond_to(:upload_from_csv)
20
+ Track.should respond_to(:upload_from_csv)
21
+ end
22
+ end
23
+
24
+ describe "upload_from_csv" do
25
+ it "should raise NoMethodError for non uploadable models" do
26
+ lambda { User.upload_from_csv("") }.should raise_error(NoMethodError)
27
+ end
28
+
29
+ it "should upload to an uploadable model" do
30
+ lambda { Album.upload_from_csv("Artist,Title,Extra\n\"John Denver\",\"All Aboard!\",1\n\"Usher\",\"Looking 4 Myself\",2")}.
31
+ should change(Album, :count).by(2)
32
+ Album.where(:artist => "John Denver", :title => "All Aboard!").count.should == 1
33
+ Album.where(:artist => "Usher", :title => "Looking 4 Myself").count.should == 1
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../lib/uploadable/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Garima"]
5
+ gem.email = ["igarimasingh@gmail.com"]
6
+ gem.description = %q{Upload your csv to activerecord model}
7
+ gem.summary = %q{This gem gives you flexibility to upload the csv to you model. It also comes packed with some customizations}
8
+ gem.homepage = "https://github.com/singhgarima/uploadable"
9
+
10
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
13
+ gem.name = "uploadable"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Uploadable::VERSION
16
+ gem.license = 'MIT'
17
+
18
+ gem.add_dependency 'fastercsv'
19
+ end
20
+
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uploadable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Garima
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fastercsv
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Upload your csv to activerecord model
31
+ email:
32
+ - igarimasingh@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .todo
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - MIT-LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - lib/uploadable.rb
45
+ - lib/uploadable/instance_methods.rb
46
+ - lib/uploadable/processor.rb
47
+ - lib/uploadable/railtie.rb
48
+ - lib/uploadable/version.rb
49
+ - spec/spec_helper.rb
50
+ - spec/support/csv/album_fixture_1.csv
51
+ - spec/support/sample_app/.gitignore
52
+ - spec/support/sample_app/Gemfile
53
+ - spec/support/sample_app/Gemfile.lock
54
+ - spec/support/sample_app/README.rdoc
55
+ - spec/support/sample_app/Rakefile
56
+ - spec/support/sample_app/app/controllers/application_controller.rb
57
+ - spec/support/sample_app/app/helpers/application_helper.rb
58
+ - spec/support/sample_app/app/mailers/.gitkeep
59
+ - spec/support/sample_app/app/models/.gitkeep
60
+ - spec/support/sample_app/app/models/album.rb
61
+ - spec/support/sample_app/app/models/track.rb
62
+ - spec/support/sample_app/app/models/user.rb
63
+ - spec/support/sample_app/config.ru
64
+ - spec/support/sample_app/config/application.rb
65
+ - spec/support/sample_app/config/boot.rb
66
+ - spec/support/sample_app/config/database.yml
67
+ - spec/support/sample_app/config/environment.rb
68
+ - spec/support/sample_app/config/environments/development.rb
69
+ - spec/support/sample_app/config/environments/production.rb
70
+ - spec/support/sample_app/config/environments/test.rb
71
+ - spec/support/sample_app/config/initializers/backtrace_silencers.rb
72
+ - spec/support/sample_app/config/initializers/inflections.rb
73
+ - spec/support/sample_app/config/initializers/mime_types.rb
74
+ - spec/support/sample_app/config/initializers/secret_token.rb
75
+ - spec/support/sample_app/config/initializers/session_store.rb
76
+ - spec/support/sample_app/config/initializers/wrap_parameters.rb
77
+ - spec/support/sample_app/config/locales/en.yml
78
+ - spec/support/sample_app/config/routes.rb
79
+ - spec/support/sample_app/db/migrate/20120624173544_create_albums.rb
80
+ - spec/support/sample_app/db/migrate/20120624173638_create_tracks.rb
81
+ - spec/support/sample_app/db/migrate/20120625055607_create_users.rb
82
+ - spec/support/sample_app/db/migrate/20120630102016_add_column_top_rated_to_tracks.rb
83
+ - spec/support/sample_app/db/schema.rb
84
+ - spec/support/sample_app/db/seeds.rb
85
+ - spec/support/sample_app/doc/README_FOR_APP
86
+ - spec/support/sample_app/lib/assets/.gitkeep
87
+ - spec/support/sample_app/lib/tasks/.gitkeep
88
+ - spec/support/sample_app/log/.gitkeep
89
+ - spec/support/sample_app/public/404.html
90
+ - spec/support/sample_app/public/422.html
91
+ - spec/support/sample_app/public/500.html
92
+ - spec/support/sample_app/public/favicon.ico
93
+ - spec/support/sample_app/public/index.html
94
+ - spec/support/sample_app/public/robots.txt
95
+ - spec/support/sample_app/script/rails
96
+ - spec/support/sample_app/test/fixtures/.gitkeep
97
+ - spec/support/sample_app/test/functional/.gitkeep
98
+ - spec/support/sample_app/test/integration/.gitkeep
99
+ - spec/support/sample_app/test/performance/browsing_test.rb
100
+ - spec/support/sample_app/test/test_helper.rb
101
+ - spec/support/sample_app/test/unit/.gitkeep
102
+ - spec/support/sample_app/vendor/assets/javascripts/.gitkeep
103
+ - spec/support/sample_app/vendor/assets/stylesheets/.gitkeep
104
+ - spec/support/sample_app/vendor/plugins/.gitkeep
105
+ - spec/uploadable/processor_spec.rb
106
+ - spec/uploadable_spec.rb
107
+ - uploadable.gemspec
108
+ homepage: https://github.com/singhgarima/uploadable
109
+ licenses:
110
+ - MIT
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 1.8.24
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: This gem gives you flexibility to upload the csv to you model. It also comes
133
+ packed with some customizations
134
+ test_files: []