Skip to content

Commit 405a16e

Browse files
committed
Add spec
1 parent 9b39c77 commit 405a16e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

spec/import_result_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'spec_helper'
2+
3+
describe ActiveAdminImport::ImportResult do
4+
context "failed_message" do
5+
let(:import_result) { ActiveAdminImport::ImportResult.new }
6+
7+
before do
8+
Author.create(name: 'John', last_name: 'Doe')
9+
Author.create(name: 'Jane', last_name: 'Roe')
10+
11+
@result = double \
12+
failed_instances: [
13+
Author.create(name: 'Jim', last_name: "Doe"), # {:last_name=>["has already been taken"]}
14+
Author.create(name: nil, last_name: 'Doe') # {:name=>["can't be blank"], :last_name=>["has already been taken"]}
15+
]
16+
end
17+
18+
it "should work without any failed instances" do
19+
expect(import_result.failed_message).to eq("")
20+
end
21+
22+
it "should work" do
23+
import_result.add(@result, 4)
24+
expect(import_result.failed_message).to eq("Last name has already been taken - Doe ; Name can't be blank - , Last name has already been taken - Doe")
25+
end
26+
27+
it "should work on limit param" do
28+
import_result.add(@result, 4)
29+
expect(import_result.failed_message(limit: 1)).to eq("Last name has already been taken - Doe")
30+
end
31+
end
32+
end

spec/support/rails_template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
generate :model, 'post title:string:uniq body:text author:references'
55

66
#Add validation
7-
inject_into_file "app/models/author.rb", " validates_presence_of :name\n", after: "Base\n"
7+
inject_into_file "app/models/author.rb", " validates_presence_of :name\n validates_uniqueness_of :last_name\n", after: "Base\n"
88
inject_into_file "app/models/post.rb", " validates_presence_of :author\n", after: ":author\n"
99

1010
# Configure default_url_options in test environment

0 commit comments

Comments
 (0)