-
-
Notifications
You must be signed in to change notification settings - Fork 70
Adding Impact Stories #415
base: main
Are you sure you want to change the base?
Conversation
…d controller actions.
…ntoller to use a block
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.
Great start! I left some comments and change requests. Feel free to reach out if you have any questions.
create_table :impact_stories do |t| | ||
t.string :title | ||
t.text :content | ||
t.integer :partner_id |
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.
Let's add a foreign key constraint here -https://guides.rubyonrails.org/active_record_migrations.html#foreign-keys
This is a really useful thing to add to ensure data integrity is kept. This prevents partner_id
from being anything that doesn't match a Partner
or if you accidentally delete a Partner
@@ -0,0 +1,11 @@ | |||
class CreateImpactStories < ActiveRecord::Migration[6.0] | |||
def change | |||
create_table :impact_stories do |t| |
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.
Let's add some database constraints to prevent it at the DB level from having incorrect data. I usually think about the database first when it comes to adding new models. Without these constraints, you could pass invalid data through if you bypass the callbacks using something like .update_column
spec/models/impact_story_spec.rb
Outdated
|
||
RSpec.describe ImpactStory, type: :model do | ||
it "returns the first part of the content according to the given limit" do | ||
impact_story = | ||
create(:impact_story, title: "For Testing", content: "Making some long content that needs to be shortened according to a given limit") |
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.
Let's use https://github.com/faker-ruby/faker to generate randomized data for tests. This is a good idea because sometimes tests pass because it relies on hardcoded data. Using randomized data helps avoid accidentally coupling the data with the actual implementation you are testing.
…re tests to ImpactStory model
Resolves #352
Description
Created a model called ImpactStories with
title
andcontent
attributes. Added a link in the sidebar as described in the issue. Made index, show, new, create, edit, and update controller actions and corresponding views with styling similar to the rest of the project. Only covers an MVP version of the issue, both file upload along with permissions for adding pictures, and sending/accessing impacts stories on the diaper side to be implemented later.Type of change
How Has This Been Tested?
Added model, request, and feature test files to test new functionality.
Screenshots