|
| 1 | +require "rails_helper" |
| 2 | + |
| 3 | +RSpec.describe "Children", type: :request do |
| 4 | + let(:partner) { create(:partner) } |
| 5 | + let(:family) { create(:family, partner_id: partner.id) } |
| 6 | + |
| 7 | + before do |
| 8 | + user = create(:user, partner: partner) |
| 9 | + sign_in(user) |
| 10 | + end |
| 11 | + |
| 12 | + describe "POST #create" do |
| 13 | + it "should create and redirect to child_path" do |
| 14 | + post children_path, params: { family_id: family.id, child: attributes_for(:child) } |
| 15 | + |
| 16 | + select_child = Child.select(:id).last |
| 17 | + expect(response).to redirect_to(child_path(select_child.id)) |
| 18 | + expect(request.flash[:notice]).to eql "Child was successfully created." |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + let(:child) { create(:child, family_id: family.id) } |
| 23 | + |
| 24 | + describe "PUT #update" do |
| 25 | + it "should update and redirect to child_path" do |
| 26 | + put child_path(child), params: { child: attributes_for(:child) } |
| 27 | + |
| 28 | + expect(response).to redirect_to(child_path(child.id)) |
| 29 | + expect(request.flash[:notice]).to eql "Child was successfully updated." |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe "DELETE #destroy" do |
| 34 | + it "should destroy and redirect to child_path" do |
| 35 | + delete child_path(child) |
| 36 | + |
| 37 | + expect(response).to redirect_to(children_path) |
| 38 | + expect(request.flash[:notice]).to eql "Child was successfully destroyed." |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + describe "POST #active" do |
| 43 | + it "should verify if child is active" do |
| 44 | + post child_active_path(child), params: { child_id: child.id } |
| 45 | + |
| 46 | + expect(child.active).to eq true |
| 47 | + end |
| 48 | + end |
| 49 | +end |
0 commit comments