From 4ce70f419aca1f2345730930de8b27659f4fb518 Mon Sep 17 00:00:00 2001 From: Emerson Manabu Araki Date: Fri, 6 Sep 2019 10:58:30 -0300 Subject: [PATCH] Add spec to ChildrenController --- spec/controllers/children_controller_spec.rb | 49 ++++++++++++++++++++ spec/rails_helper.rb | 1 + 2 files changed, 50 insertions(+) create mode 100644 spec/controllers/children_controller_spec.rb diff --git a/spec/controllers/children_controller_spec.rb b/spec/controllers/children_controller_spec.rb new file mode 100644 index 00000000..90798903 --- /dev/null +++ b/spec/controllers/children_controller_spec.rb @@ -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 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4f4e80c4..c189d302 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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