-
Notifications
You must be signed in to change notification settings - Fork 2
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
[40] Create Rails SecurityLog model #96
Conversation
spec/models/security_log_spec.rb
Outdated
it 'validates presence of action' do | ||
security_log = described_class.new(action: nil) | ||
expect(security_log).not_to be_valid | ||
expect(security_log.errors[:action]).to include("can't be blank") | ||
end |
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.
can this use the new shared_example?
it 'validates presence of action' do | |
security_log = described_class.new(action: nil) | |
expect(security_log).not_to be_valid | |
expect(security_log.errors[:action]).to include("can't be blank") | |
end | |
it_behaves_like 'a model with required attributes', [:actoin] |
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.
I was getting errors saying when i did a binding pry i believe the issue was with the set_logged_at so i will try it again with the other suggestion you commented
def set_logged_at | ||
self.logged_at ||= DateTime.now | ||
end |
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.
I just reviewed a similar issue on a different PR and found this SO solution. I think we can leverage the timestamp_attributes_for_create
method like this:
private_class_method
def self.timestamp_attributes_for_create
super << 'logged_at'
end
Co-authored-by: Stephen Chudleigh <stepchud@users.noreply.github.com>
|
||
RSpec.describe SecurityLog do | ||
describe 'Security Log validations' do | ||
it_behaves_like 'a model with required attributes', [:action] |
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.
@bilalhankins I added this line, works fine for me
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.
g2g
Created rails SecurityLog Model
Added basic spec tests