awesome_imports 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency 'activesupport', ['>= 3.0.0']
22
22
  s.add_dependency 'activemodel', ['>= 3.0.0']
23
+ s.add_dependency 'activerecord', ['>= 3.0.0']
23
24
  s.add_dependency 'actionpack', ['>= 3.0.0']
24
25
  s.add_development_dependency 'rake', [">= 0"]
25
26
  s.add_development_dependency 'rspec', ['>= 0']
@@ -1,5 +1,7 @@
1
1
  require "csv"
2
2
  require "active_model"
3
+ require "active_record"
4
+ require "active_record/validations"
3
5
  require "active_support/core_ext"
4
6
 
5
7
  module AwesomeImports
@@ -15,8 +17,8 @@ module AwesomeImports
15
17
  def id
16
18
  end
17
19
 
18
- define_attribute_methods ["csv_file"]
19
- attr_accessor :csv_file
20
+ define_attribute_methods ["csv_file", "user"]
21
+ attr_accessor :csv_file, :user
20
22
 
21
23
  def initialize(attr = {})
22
24
  attribute = attr.with_indifferent_access
@@ -77,7 +79,7 @@ module AwesomeImports
77
79
 
78
80
  def update
79
81
  @records = parse_csv_from_stored_file
80
- Keyword.transaction do
82
+ ActiveRecord::Base.transaction do
81
83
  records.each do |record|
82
84
  record.save!
83
85
  end
@@ -90,6 +92,10 @@ module AwesomeImports
90
92
  false
91
93
  end
92
94
 
95
+ def has_error?
96
+ @records.any?{ |record| !record.errors.empty? }
97
+ end
98
+
93
99
  private
94
100
  # TODO: Remove old csv files
95
101
  def remove_old_stored_csvs
@@ -19,6 +19,7 @@ module AwesomeImports
19
19
 
20
20
  def create
21
21
  import = resource_class.new(params[import_name.to_sym])
22
+ import.user = current_user if respond_to?(:current_user)
22
23
  import.confirm
23
24
  session[import_name.to_sym] = import.store_attached_csv_file
24
25
 
@@ -27,6 +28,7 @@ module AwesomeImports
27
28
 
28
29
  def update
29
30
  import = resource_class.restore_from_file(session[import_name.to_sym])
31
+ import.user = current_user if respond_to?(:current_user)
30
32
  if import.update
31
33
  flash[:notice] = I18n.t("awesome_imports.controller.success")
32
34
  session[import_name.to_sym] = nil
@@ -1,3 +1,3 @@
1
1
  module AwesomeImports
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -57,5 +57,10 @@ describe AwesomeImports::CsvImport do
57
57
  end
58
58
 
59
59
  describe "#update" do
60
+ it "should success to call" do
61
+ pending
62
+ @import.stub(:parse_csv_from_stored_file).and_return([])
63
+ @import.update
64
+ end
60
65
  end
61
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_imports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-21 00:00:00.000000000 +09:00
12
+ date: 2011-11-22 00:00:00.000000000 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2155000740 !ruby/object:Gem::Requirement
17
+ requirement: &2157453280 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2155000740
25
+ version_requirements: *2157453280
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activemodel
28
- requirement: &2155000220 !ruby/object:Gem::Requirement
28
+ requirement: &2157452760 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,21 @@ dependencies:
33
33
  version: 3.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2155000220
36
+ version_requirements: *2157452760
37
+ - !ruby/object:Gem::Dependency
38
+ name: activerecord
39
+ requirement: &2157452280 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: 3.0.0
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2157452280
37
48
  - !ruby/object:Gem::Dependency
38
49
  name: actionpack
39
- requirement: &2154999740 !ruby/object:Gem::Requirement
50
+ requirement: &2157451800 !ruby/object:Gem::Requirement
40
51
  none: false
41
52
  requirements:
42
53
  - - ! '>='
@@ -44,10 +55,10 @@ dependencies:
44
55
  version: 3.0.0
45
56
  type: :runtime
46
57
  prerelease: false
47
- version_requirements: *2154999740
58
+ version_requirements: *2157451800
48
59
  - !ruby/object:Gem::Dependency
49
60
  name: rake
50
- requirement: &2154999260 !ruby/object:Gem::Requirement
61
+ requirement: &2157451320 !ruby/object:Gem::Requirement
51
62
  none: false
52
63
  requirements:
53
64
  - - ! '>='
@@ -55,10 +66,10 @@ dependencies:
55
66
  version: '0'
56
67
  type: :development
57
68
  prerelease: false
58
- version_requirements: *2154999260
69
+ version_requirements: *2157451320
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: rspec
61
- requirement: &2154998780 !ruby/object:Gem::Requirement
72
+ requirement: &2157450840 !ruby/object:Gem::Requirement
62
73
  none: false
63
74
  requirements:
64
75
  - - ! '>='
@@ -66,7 +77,7 @@ dependencies:
66
77
  version: '0'
67
78
  type: :development
68
79
  prerelease: false
69
- version_requirements: *2154998780
80
+ version_requirements: *2157450840
70
81
  description: Cool and simple data importer for rails by CSV
71
82
  email:
72
83
  - matsumura.aki@gmail.com