-
Notifications
You must be signed in to change notification settings - Fork 67
Auto Skip Update Without Changes #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,17 @@ | |
describe CSVImporter do | ||
# Mimics an active record model | ||
class User | ||
include Virtus.model | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
include ActiveModel::Validations | ||
include ActiveModel::Dirty | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry it was hard to integrate |
||
|
||
attribute :id | ||
attribute :email | ||
attribute :f_name | ||
attribute :l_name | ||
attribute :confirmed_at | ||
attribute :created_by_user_id | ||
attribute :custom_fields, Hash | ||
attribute :custom_fields, default: -> { Hash.new } | ||
|
||
validates_presence_of :email | ||
validates_format_of :email, with: /[^@]+@[^@]/ # contains one @ symbol | ||
|
@@ -25,30 +26,34 @@ def self.transaction | |
end | ||
|
||
def persisted? | ||
!!id | ||
!!self.id | ||
end | ||
|
||
def save | ||
return false unless valid? | ||
|
||
unless persisted? | ||
@id = rand(100) | ||
self.id = rand(100) | ||
self.class.store << self | ||
end | ||
|
||
changes_applied | ||
|
||
true | ||
end | ||
|
||
def self.find_by(attributes) | ||
store.find { |u| attributes.all? { |k, v| u.attributes[k] == v } } | ||
store.find { |u| attributes.all? { |k, v| u.public_send(k) == v } } | ||
end | ||
|
||
def self.reset_store! | ||
@store = Set.new | ||
|
||
User.new( | ||
email: "[email protected]", f_name: "mark", l_name: "lee", confirmed_at: Time.new(2012) | ||
).save | ||
user = User.new | ||
{ email: "[email protected]", f_name: "mark", l_name: "lee", confirmed_at: Time.new(2012) }.each do |k,v| | ||
user.public_send("#{k}=",v) | ||
end | ||
user.save | ||
|
||
@store | ||
end | ||
|
@@ -633,8 +638,20 @@ class ImportUserCSVByFirstName | |
end | ||
|
||
import.run! | ||
expect(import.report.valid_rows.size).to eq(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really confusing, should have 2 valid rows. We defined a rule to skip the import or not, that doesn't make input values invalid, just make this import not suitable to go in. I mean no need to find out what is wrong with the CSV. |
||
expect(import.report.message).to eq "Import completed: 1 created, 1 update skipped" | ||
end | ||
|
||
it "if no changes detected" do | ||
csv_content = "email,confirmed,first_name,last_name | ||
[email protected],true,mark,lee" | ||
import = ImportUserCSV.new(content: csv_content) | ||
|
||
import.run! | ||
|
||
expect(import.report.valid_rows.size).to eq(0) | ||
expect(import.report.message).to eq "Import completed: 1 update skipped" | ||
end | ||
|
||
it "doesn't call skip! twice" do | ||
csv_content = "email,confirmed,first_name,last_name | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed by AM