Skip to content
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

Merged
merged 8 commits into from
Aug 9, 2024
Merged

Conversation

bilalhankins
Copy link
Contributor

Created rails SecurityLog Model
Added basic spec tests

@bilalhankins bilalhankins requested a review from stepchud July 31, 2024 21:31
@r-bartlett-gsa r-bartlett-gsa added this to the Sprint 08/13/24 milestone Jul 31, 2024
Comment on lines 23 to 27
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
Copy link
Contributor

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?

Suggested change
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]

Copy link
Contributor Author

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

Comment on lines +46 to +48
def set_logged_at
self.logged_at ||= DateTime.now
end
Copy link
Contributor

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


RSpec.describe SecurityLog do
describe 'Security Log validations' do
it_behaves_like 'a model with required attributes', [:action]
Copy link
Contributor

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

Copy link
Contributor

@stepchud stepchud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

g2g

@stepchud stepchud merged commit 6ade342 into dev Aug 9, 2024
8 checks passed
@stepchud stepchud deleted the 40/create-security-log-model branch August 9, 2024 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants