Skip to content
This repository has been archived by the owner on Nov 6, 2021. It is now read-only.

Commit

Permalink
Add spec to ChildrenController
Browse files Browse the repository at this point in the history
  • Loading branch information
EmersonAraki committed Sep 16, 2019
1 parent 83fec1c commit 4ce70f4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions spec/controllers/children_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require "rails_helper"

RSpec.describe "Children", type: :request do
let(:partner) { create(:partner) }
let(:family) { create(:family, partner_id: partner.id) }

before do
user = create(:user, partner: partner)
sign_in(user)
end

describe "POST #create" do
it "should create and redirect to child_path" do
post children_path, params: { family_id: family.id, child: attributes_for(:child) }

select_child = Child.select(:id).last
expect(response).to redirect_to(child_path(select_child.id))
expect(request.flash[:notice]).to eql "Child was successfully created."
end
end

let(:child) { create(:child, family_id: family.id) }

describe "PUT #update" do
it "should update and redirect to child_path" do
put child_path(child), params: { child: attributes_for(:child) }

expect(response).to redirect_to(child_path(child.id))
expect(request.flash[:notice]).to eql "Child was successfully updated."
end
end

describe "DELETE #destroy" do
it "should destroy and redirect to child_path" do
delete child_path(child)

expect(response).to redirect_to(children_path)
expect(request.flash[:notice]).to eql "Child was successfully destroyed."
end
end

describe "POST #active" do
it "should verify if child is active" do
post child_active_path(child), params: { child_id: child.id }

expect(child.active).to eq true
end
end
end
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
# sign_in helpers for feature specs
config.include Devise::Test::IntegrationHelpers, type: :feature
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::IntegrationHelpers, type: :request
config.extend ControllerMacros, type: :controller
config.include FactoryBot::Syntax::Methods
end

0 comments on commit 4ce70f4

Please sign in to comment.