csv_magic 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,4 +7,6 @@ spec/dummy/db
7
7
  Gemfile.lock
8
8
  pkg/*
9
9
 
10
- /spec/dummy/log/test.log
10
+ /spec/dummy/log/test.log
11
+ .rvmrc
12
+ spec/dummy/db/test.sqlite3
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## Description
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/magiclabs/csv_magic.png?branch=master)](http://travis-ci.org/magiclabs/csv_magic)
4
+
3
5
  This gem adds an import action in every controller you like to be able to handle csv imports.
4
6
  It includes the complete workflow:
5
7
 
@@ -1,10 +1,10 @@
1
- <h1><%= t(:import_csv_file) %></h1>
1
+ <h1><%= csv_magic_t(:import_csv_file) %></h1>
2
2
 
3
- <p><%= t(:please_choose_a_csv_file) %>:</p>
3
+ <p><%= csv_magic_t(:please_choose_a_csv_file) %>:</p>
4
4
 
5
5
  <%= form_tag(url_for(:action => 'import'), :multipart => true) do %>
6
6
  <div class="field">
7
7
  <%= file_field_tag 'file' %>
8
- <%= submit_tag t(:import) %>
8
+ <%= submit_tag csv_magic_t(:import) %>
9
9
  </div>
10
10
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <div class="csv_magic_import_errros">
2
- <h2><%= t(:import_errors) %>:</h2>
2
+ <h2><%= csv_magic_t(:import_errors) %>:</h2>
3
3
  <ol>
4
4
  <%- @csv_import_errors.each do |error| -%>
5
5
  <li><%= error.full_messages %></li>
@@ -1,6 +1,6 @@
1
- <h1><%= t(:import_csv_file) %></h1>
1
+ <h1><%= csv_magic_t(:import_csv_file) %></h1>
2
2
 
3
- <p><%= t(:please_map_columns) %></p>
3
+ <p><%= csv_magic_t(:please_map_columns) %></p>
4
4
 
5
5
  <%= form_tag nil, :id => 'map_fields_form', :method => :post do -%>
6
6
  <%= hidden_field_tag :filename, @mapper.filename %>
@@ -33,10 +33,10 @@
33
33
  <div class="option">
34
34
  <p>
35
35
  <%= check_box_tag 'ignore_first_row', '1', true %>
36
- <%= label_tag 'ignore_first_row', t(:ignore_first_row) %>
36
+ <%= label_tag 'ignore_first_row', csv_magic_t(:ignore_first_row) %>
37
37
  </p>
38
38
  </div>
39
39
  <div class="action">
40
- <%= submit_tag t(:import) %>
40
+ <%= submit_tag csv_magic_t(:import) %>
41
41
  </div>
42
42
  <%- end -%>
data/csv_magic.gemspec CHANGED
@@ -19,5 +19,4 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency 'rails', ['~> 3.1.4']
20
20
  s.add_development_dependency 'rspec-rails', ["~> 2.8.0"]
21
21
  s.add_development_dependency 'sqlite3', ["~> 1.3.5"]
22
- s.add_development_dependency 'capybara', ['>= 0.4.0']
23
22
  end
@@ -55,10 +55,10 @@ module CSVMagic
55
55
  if params[:fields]
56
56
  create_resource_items_from_csv(resource_class)
57
57
  if @csv_import_errors.empty?
58
- flash[:notice] = t(:successfully_imported_data)
58
+ flash[:notice] = csv_magic_t(:successfully_imported_data)
59
59
  redirect_to :action => :index
60
60
  else
61
- flash[:warning] = t(:errors_while_importing)
61
+ flash[:warning] = csv_magic_t(:errors_while_importing)
62
62
  render 'csv_magic/import_errors'
63
63
  end
64
64
  #no mapping yet
@@ -68,13 +68,13 @@ module CSVMagic
68
68
  render 'csv_magic/mapper'
69
69
  end
70
70
  rescue MissingFileContentsError
71
- flash[:warning] = t(:please_upload_a_csv_file)
71
+ flash[:warning] = csv_magic_t(:please_upload_a_csv_file)
72
72
  render_csv_import_form
73
73
  rescue ::CSV::MalformedCSVError => e
74
- flash[:warning] = t(:csv_file_has_wrong_format) % {:error => e.message}
74
+ flash[:warning] = csv_magic_t(:csv_file_has_wrong_format) % {:error => e.message}
75
75
  render_csv_import_form
76
76
  rescue ::Errno::ENOENT
77
- flash[:warning] = t(:file_not_on_server_any_more)
77
+ flash[:warning] = csv_magic_t(:file_not_on_server_any_more)
78
78
  render_csv_import_form
79
79
  rescue Exception => e
80
80
  flash[:warning] = e.message
@@ -3,7 +3,7 @@ module CSVMagic
3
3
 
4
4
  def self.included(controller)
5
5
  if controller.respond_to?(:helper_method)
6
- controller.send(:helper_method, [:t])
6
+ controller.send(:helper_method, [:csv_magic_t])
7
7
  end
8
8
  end
9
9
 
@@ -14,7 +14,7 @@ module CSVMagic
14
14
  # The keys are scoped into +csv_magic+ namespace.
15
15
  # Even if you pass a scope this is scoped under +csv_magic+.
16
16
  #
17
- def t(key, options={})
17
+ def csv_magic_t(key, options={})
18
18
  scope = options[:scope].blank? ? 'csv_magic' : "csv_magic.#{options.delete(:scope)}"
19
19
  ::I18n.t(key, {:scope => scope, :default => key.to_s.humanize}.merge(options))
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module CSVMagic
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,2 +1,3 @@
1
1
  class Person < ActiveRecord::Base
2
+ validates_presence_of :lastname
2
3
  end
@@ -0,0 +1,3 @@
1
+ Lastname; Given Name
2
+ Doe; John
3
+ Mustermann; Max
@@ -1,9 +1,14 @@
1
- require "rspec"
2
- require 'csv_magic/importer'
1
+ require "spec_helper"
3
2
 
4
- describe CSVMagic::Importer do
3
+ module CSVMagic
4
+ describe Importer do
5
5
 
6
- describe "raw_data" do
7
- it "should return an array from the given csv-file"
8
- end
9
- end
6
+ describe "raw_data", :type => :request do
7
+ it "should return an array from the given csv-file" do
8
+ @file = fixture_file_upload('/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
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CSVMagic do
4
- include Capybara::DSL
5
4
 
6
5
  it "should be valid" do
7
6
  CSVMagic.should be_a(Module)
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ describe "Controller#import action." do
4
+
5
+ describe "Sending a get request" do
6
+ it "renders the import form." do
7
+ get 'people/import'
8
+ response.body.should match(/please choose a csv file/i)
9
+ end
10
+ end
11
+
12
+ describe "Sending a post request" do
13
+
14
+ before(:each) do
15
+ @file = fixture_file_upload('/files/file.csv', 'text/csv')
16
+ end
17
+
18
+ context "if csv is given in params" do
19
+ it "it renders the mapper view." do
20
+ post 'people/import', {:file => @file}
21
+ response.body.should match(/Please map columns/)
22
+ end
23
+ end
24
+
25
+ context "if mapping is given in params" do
26
+ it "it redirects to index view." do
27
+ @file_handler = CSVMagic::FileHandler.new
28
+ @file_handler.save_temp_file(@file)
29
+ post 'people/import', {:filename => @file_handler.filename, :fields => {"1" => "Firstname", "2" => "Lastname"}}
30
+ response.code.should == "302"
31
+ response.should redirect_to(people_path)
32
+ end
33
+ end
34
+
35
+ context "if wrong mapping is given in params" do
36
+ it "it shows the import errors view." do
37
+ @file_handler = CSVMagic::FileHandler.new
38
+ @file_handler.save_temp_file(@file)
39
+ post 'people/import', {:filename => @file_handler.filename, :fields => {"1" => "Firstname"}}
40
+ response.body.should match /import errors/i
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,13 +11,9 @@ ActionMailer::Base.default_url_options[:host] = "test.com"
11
11
 
12
12
  Rails.backtrace_cleaner.remove_silencers!
13
13
 
14
- # Configure capybara for integration testing
15
- require "capybara/rails"
16
- Capybara.default_driver = :rack_test
17
- Capybara.default_selector = :css
18
-
19
14
  # Run any available migration
20
15
  ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
16
+ ActionController::TestCase.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
21
17
 
22
18
  # Load support files
23
19
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
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.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70288960293000 !ruby/object:Gem::Requirement
17
+ requirement: &70132287098180 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.1.4
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70288960293000
25
+ version_requirements: *70132287098180
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec-rails
28
- requirement: &70288960308400 !ruby/object:Gem::Requirement
28
+ requirement: &70132287096580 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.8.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70288960308400
36
+ version_requirements: *70132287096580
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sqlite3
39
- requirement: &70288960306880 !ruby/object:Gem::Requirement
39
+ requirement: &70132287112120 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,18 +44,7 @@ dependencies:
44
44
  version: 1.3.5
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70288960306880
48
- - !ruby/object:Gem::Dependency
49
- name: capybara
50
- requirement: &70288960305660 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: 0.4.0
56
- type: :development
57
- prerelease: false
58
- version_requirements: *70288960305660
47
+ version_requirements: *70132287112120
59
48
  description: Provides controller actions, views and field mapping for data from a
60
49
  csv file.
61
50
  email:
@@ -107,7 +96,6 @@ files:
107
96
  - spec/dummy/config/locales/en.yml
108
97
  - spec/dummy/config/routes.rb
109
98
  - spec/dummy/db/migrate/20110808105053_create_people.rb
110
- - spec/dummy/db/test.sqlite3
111
99
  - spec/dummy/log/production.log
112
100
  - spec/dummy/log/server.log
113
101
  - spec/dummy/public/404.html
@@ -124,10 +112,10 @@ files:
124
112
  - spec/dummy/script/rails
125
113
  - spec/dummy_data.csv
126
114
  - spec/file_handler_spec.rb
115
+ - spec/fixtures/files/file.csv
127
116
  - spec/importer_spec.rb
128
- - spec/integration/get_request_spec.rb
129
- - spec/integration/post_request_spec.rb
130
117
  - spec/integration/resource_integration_spec.rb
118
+ - spec/requests/import_action_spec.rb
131
119
  - spec/spec_helper.rb
132
120
  - spec/test.file
133
121
  homepage: https://github.com/magiclabs/csv_magic
@@ -144,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
132
  version: '0'
145
133
  segments:
146
134
  - 0
147
- hash: 246439835387247952
135
+ hash: -983402596518867676
148
136
  required_rubygems_version: !ruby/object:Gem::Requirement
149
137
  none: false
150
138
  requirements:
@@ -153,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
141
  version: '0'
154
142
  segments:
155
143
  - 0
156
- hash: 246439835387247952
144
+ hash: -983402596518867676
157
145
  requirements: []
158
146
  rubyforge_project: csv_magic
159
147
  rubygems_version: 1.8.15
Binary file
@@ -1 +0,0 @@
1
- require "spec_helper"
@@ -1,13 +0,0 @@
1
- require "rspec"
2
-
3
- describe CSVMagic do
4
- context "when csv is given as param" do
5
- it "renders the mapper view"
6
- end
7
- context "when mapping and filename is given as param" do
8
- it "saves the csv-lines as resource-objects"
9
- end
10
- context "when csv has been imported" do
11
- it "redirects to resources index"
12
- end
13
- end