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 6, 2019
1 parent 83fec1c commit 7669f10
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions spec/controllers/children_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require "rails_helper"

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

before do
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) }

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

describe "PUT #update" do
let(:child) { create(:child, family_id: family.id) }

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
let(:child) { create(:child, family_id: family.id) }

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
let(:child) { create(:child, family_id: family.id) }

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 7669f10

Please sign in to comment.