csv_magic 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/Gemfile +3 -1
- data/README.md +1 -1
- data/csv_magic.gemspec +3 -3
- data/lib/csv_magic/controller_actions.rb +10 -8
- data/lib/csv_magic/version.rb +1 -1
- data/spec/importer_spec.rb +9 -9
- data/spec/requests/import_action_spec.rb +1 -1
- metadata +13 -13
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -5,7 +5,9 @@ gemspec
|
|
5
5
|
|
6
6
|
group :development do
|
7
7
|
if !ENV["CI"]
|
8
|
-
gem '
|
8
|
+
gem 'ruby-debug-base19', '~> 0.11.26', :platform => :ruby_19
|
9
|
+
gem 'linecache19', '~> 0.5.13', :platform => :ruby_19
|
10
|
+
gem 'ruby-debug19', '~> 0.11.6', :require => 'ruby-debug', :platform => :ruby_19
|
9
11
|
gem 'ruby-debug', :platform => :ruby_18
|
10
12
|
end
|
11
13
|
end
|
data/README.md
CHANGED
data/csv_magic.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
s.add_development_dependency 'rails', ['~> 3.
|
21
|
-
s.add_development_dependency 'rspec-rails'
|
22
|
-
s.add_development_dependency 'sqlite3'
|
20
|
+
s.add_development_dependency 'rails', ['~> 3.2.6']
|
21
|
+
s.add_development_dependency 'rspec-rails'
|
22
|
+
s.add_development_dependency 'sqlite3'
|
23
23
|
end
|
@@ -2,12 +2,14 @@ module CSVMagic
|
|
2
2
|
module ControllerActions
|
3
3
|
|
4
4
|
def self.included(base)
|
5
|
+
base.send(:class_attribute, :map_fields_options)
|
5
6
|
base.extend(ClassMethods)
|
6
7
|
base.csv_magic_config
|
7
8
|
base.send(:include, I18nHelpers)
|
8
9
|
end
|
9
10
|
|
10
11
|
module ClassMethods
|
12
|
+
|
11
13
|
def csv_magic_config( options = {} )
|
12
14
|
defaults = {
|
13
15
|
:action => :import,
|
@@ -15,7 +17,7 @@ module CSVMagic
|
|
15
17
|
:file_field => :file
|
16
18
|
}
|
17
19
|
options = defaults.merge(options)
|
18
|
-
|
20
|
+
self.map_fields_options = options
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -63,23 +65,23 @@ module CSVMagic
|
|
63
65
|
end
|
64
66
|
#no mapping yet
|
65
67
|
else
|
66
|
-
@mapper = Importer.new(params, self.class.
|
68
|
+
@mapper = Importer.new(params, self.class.map_fields_options)
|
67
69
|
@raw_data = @mapper.raw_data
|
68
70
|
render 'csv_magic/mapper'
|
69
71
|
end
|
70
72
|
rescue MissingFileContentsError
|
71
|
-
flash[:
|
73
|
+
flash[:warning] = csv_magic_t(:please_upload_a_csv_file)
|
72
74
|
render_csv_import_form
|
73
75
|
rescue ::CSV::MalformedCSVError => e
|
74
|
-
flash[:
|
76
|
+
flash[:warning] = csv_magic_t(:csv_file_has_wrong_format) % {:error => e.message}
|
75
77
|
render_csv_import_form
|
76
78
|
rescue ::Errno::ENOENT
|
77
|
-
flash[:
|
79
|
+
flash[:warning] = csv_magic_t(:file_not_on_server_any_more)
|
78
80
|
render_csv_import_form
|
79
81
|
rescue Exception => e
|
80
|
-
flash[:
|
81
|
-
|
82
|
-
|
82
|
+
flash[:warning] = e.message
|
83
|
+
logger.error(e.message)
|
84
|
+
logger.error(e.backtrace.join("\n"))
|
83
85
|
render_csv_import_form
|
84
86
|
end
|
85
87
|
|
data/lib/csv_magic/version.rb
CHANGED
data/spec/importer_spec.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
module CSVMagic
|
4
|
-
|
4
|
+
describe Importer do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
describe "raw_data", :type => :request do
|
7
|
+
it "should return an array from the given csv-file" do
|
8
|
+
@file = fixture_file_upload(File.join(File.dirname(__FILE__), 'fixtures/files/file.csv'), 'text/csv')
|
9
|
+
@importer = Importer.new({:file => @file}, {:file_field => :file})
|
10
|
+
@importer.raw_data.should == [["Lastname", " Given Name"], ["Doe", " John"], ["Mustermann", " Max"]]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
14
|
end
|
@@ -12,7 +12,7 @@ describe "Controller#import action." do
|
|
12
12
|
describe "Sending a post request" do
|
13
13
|
|
14
14
|
before(:each) do
|
15
|
-
@file = fixture_file_upload('/files/file.csv', 'text/csv')
|
15
|
+
@file = fixture_file_upload(File.join(File.dirname(__FILE__), '..', 'fixtures/files/file.csv'), 'text/csv')
|
16
16
|
end
|
17
17
|
|
18
18
|
context "if csv is given in params" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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: 2012-
|
13
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 3.
|
22
|
+
version: 3.2.6
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,39 +27,39 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: 3.
|
30
|
+
version: 3.2.6
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: rspec-rails
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
none: false
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ! '>='
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
38
|
+
version: '0'
|
39
39
|
type: :development
|
40
40
|
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ! '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: '0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ! '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: '0'
|
63
63
|
description: Provides controller actions, views and field mapping for data from a
|
64
64
|
csv file.
|
65
65
|
email:
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
version: '0'
|
155
155
|
segments:
|
156
156
|
- 0
|
157
|
-
hash: -
|
157
|
+
hash: -2326911074991617375
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project: csv_magic
|
160
160
|
rubygems_version: 1.8.24
|