Best Factory_bot_ruby code snippet using FactoryBot.associations
draft_changes_proxy_spec.rb
Source:draft_changes_proxy_spec.rb
...343 end344 it 'returns a DraftChangesProxy of the current value for a belongs_to association' do345 expect(subject.current_value("gender")).to eq(proxy.new(gender, transaction))346 end347 it "returns an array of DraftChangesProxy's of the current values for has_many associations" do348 expected_values = [349 proxy.new(contact1, transaction),350 proxy.new(contact2, transaction)351 ]352 expect(subject.current_value("contact_addresses")).to match_array(expected_values)353 end354 end355 end356 describe '#new_value' do357 let!(:name) { 'Person Name' }358 let!(:gender) { FactoryBot.create(:gender) }359 let!(:person) { FactoryBot.create(:person, name: name, gender: gender) }360 let!(:contact) { FactoryBot.create(:contact_address, contactable: person) }361 context 'when there is no Draft' do362 let(:subject) { proxy.new(person, transaction) }363 it 'returns the current value for a simple attribute' do364 expect(subject.new_value("name")).to eq(name)365 end366 it 'returns a DraftChangesProxy of the current value for a belongs_to association' do367 expect(subject.new_value("gender")).to eq(proxy.new(gender, transaction))368 end369 it "returns an array of DraftChangesProxy's of the current values for has_many associations" do370 expected_values = [proxy.new(contact, transaction)]371 expect(subject.new_value("contact_addresses")).to match_array(expected_values)372 end373 end374 context 'when there is a Draft' do375 let(:subject) { proxy.new(draft) }376 context 'simple attributes' do377 let(:draft) do378 FactoryBot.create(379 :draft,380 draft_transaction: transaction,381 draftable: person,382 draft_changes: changes383 )384 end385 context 'when there are no changes to the attribute' do386 let(:changes) { {} }387 it 'returns the current value for a simple attribute' do388 expect(subject.new_value("name")).to eq(name)389 end390 end391 context 'when the new value is non-nil' do392 let(:new_name) { 'Person New Name' }393 let(:changes) { { "name" => [name, new_name] } }394 it 'returns the new value for a simple attribute' do395 expect(subject.new_value("name")).to eq(new_name)396 end397 end398 context 'when the new value is nil' do399 let(:new_name) { nil }400 let(:changes) { { "name" => [name, new_name] } }401 it 'returns the nil new value for a simple attribute' do402 expect(subject.new_value("name")).to be(nil)403 end404 end405 end406 context 'belongs_to associations' do407 let(:draft) do408 FactoryBot.create(409 :draft,410 draft_transaction: transaction,411 draftable: contact,412 draft_changes: changes413 )414 end415 context 'when there are no changes to the association' do416 let(:changes) { {} }417 it 'returns a DraftChangesProxy of the current value for a belongs_to association' do418 expect(subject.new_value("contactable")).to eq(proxy.new(person, transaction))419 end420 end421 context 'when the new value is an already persisted object' do422 let(:membership) { FactoryBot.create(:person) }423 let(:changes) do424 {425 "contactable" => [426 { const_type => person.class.name, const_id => person.id },427 { const_type => membership.class.name, const_id => membership.id }428 ]429 }430 end431 it 'returns a DraftChangesProxy of the new value for a belongs_to association' do432 expect(subject.new_value("contactable")).to eq(proxy.new(membership, transaction))433 end434 end435 context 'when the new value is a persisted draft in the same transaction' do436 let(:membership) do437 FactoryBot.build(438 :membership,439 :with_persisted_draft,440 draft_transaction: transaction441 )442 end443 let(:changes) do444 {445 "contactable" => [446 { const_type => person.class.name, const_id => person.id },447 { const_type => Draft.name, const_id => membership.draft_pending_approval.id }448 ]449 }450 end451 it 'returns a DraftChangesProxy of the new draft for a belongs_to association' do452 expect(subject.new_value("contactable")).to eq(proxy.new(membership.draft_pending_approval, transaction))453 end454 end455 context 'when the new value is a persisted draft in another transaction' do456 let(:membership) { FactoryBot.build(:membership, :with_persisted_draft) }457 let(:changes) do458 {459 "contactable" => [460 { const_type => person.class.name, const_id => person.id },461 { const_type => Draft.name, const_id => membership.draft_pending_approval.id }462 ]463 }464 end465 it 'raises an ArgumentError' do466 expect do467 subject.new_value("contactable")468 end.to raise_error(ArgumentError)469 end470 end471 context 'when the new value is nil' do472 let(:changes) do473 {474 "contactable" => [475 { const_type => person.class.name, const_id => person.id },476 nil477 ]478 }479 end480 it 'returns the nil new value for a belongs_to association' do481 expect(subject.new_value("contactable")).to be(nil)482 end483 end484 end485 end486 end487 context 'has_many associations' do488 let!(:name) { 'Person Name' }489 let!(:gender) { FactoryBot.create(:gender) }490 let!(:person) { FactoryBot.create(:person, name: name, gender: gender) }491 let!(:contact) { FactoryBot.create(:contact_address, contactable: person) }492 context 'non-polymorphic has_many associations' do493 context 'when there is a draftable' do494 let(:subject) { proxy.new(gender, transaction) }495 let(:association) { "people" }496 context 'when no additional drafts referencing the draftable have been created' do497 it "#new_value returns the DraftChangesProxy's for the current values" do498 expected_values = [proxy.new(person, transaction)]499 expect(subject.new_value(association)).to match_array(expected_values)500 end501 it '#associations_added returns an empty array' do502 expect(subject.associations_added(association)).to eql([])503 end504 it '#associations_removed returns an empty array' do505 expect(subject.associations_removed(association)).to eql([])506 end507 end508 context 'when an additional draft referencing the draftable has been created' do509 let(:another_person) do510 FactoryBot.build(511 :person,512 :with_persisted_draft,513 draft_transaction: transaction,514 draft_action_type: Draft::CREATE,515 draft_changes: {516 "gender" => [517 nil,518 { const_type => Gender.name, const_id => gender.id }519 ]520 }521 )522 end523 it "#new_value returns an the DraftChangesProxy's for the current values and newly drafted values" do524 expected_values = [525 proxy.new(person, transaction),526 proxy.new(another_person.draft_pending_approval, transaction)527 ]528 expect(subject.new_value(association)).to match_array(expected_values)529 end530 it "#associations_added returns the DraftChangesProxy's for the newly drafted values" do531 expected_values = [532 proxy.new(another_person.draft_pending_approval, transaction)533 ]534 expect(subject.associations_added(association)).to match_array(expected_values)535 end536 it '#associations_removed returns an empty array' do537 expect(subject.associations_removed(association)).to eql([])538 end539 end540 context 'when a draft referencing the draftable has been created in another transaction' do541 let(:another_person) do542 FactoryBot.build(543 :person,544 :with_persisted_draft,545 draft_action_type: Draft::CREATE,546 draft_changes: {547 "gender" => [548 nil,549 { const_type => Gender.name, const_id => gender.id }550 ]551 }552 )553 end554 it "#new_value returns the DraftChangesProxy's for the current values" do555 expected_values = [proxy.new(person, transaction)]556 expect(subject.new_value(association)).to match_array(expected_values)557 end558 it '#associations_added returns an empty array' do559 expect(subject.associations_added(association)).to eql([])560 end561 it '#associations_removed returns an empty array' do562 expect(subject.associations_removed(association)).to eql([])563 end564 end565 context 'when a draft removing the draftable reference from the existing association has been created' do566 let!(:person_draft) do567 FactoryBot.create(568 :draft,569 draft_transaction: transaction,570 draftable: person,571 draft_action_type: Draft::UPDATE,572 draft_changes: {573 "gender" => [574 { const_type => Gender.name, const_id => gender.id },575 nil576 ]577 }578 )579 end580 it "#new_value returns an empty array" do581 expect(subject.new_value(association)).to eql([])582 end583 it '#associations_added returns an empty array' do584 expect(subject.associations_added(association)).to eql([])585 end586 it "#associations_removed returns the DraftChangesProxy's for the draft" do587 expected_values = [proxy.new(person, transaction)]588 expect(subject.associations_removed(association)).to match_array(expected_values)589 end590 end591 context 'when a draft deleting the associated object has been created' do592 let!(:person_draft) do593 FactoryBot.create(594 :draft,595 draft_transaction: transaction,596 draftable: person,597 draft_action_type: Draft::DELETE,598 draft_changes: {}599 )600 end601 it "#new_value returns an empty array" do602 expect(subject.new_value(association)).to eql([])603 end604 it '#associations_added returns an empty array' do605 expect(subject.associations_added(association)).to eql([])606 end607 it "#associations_removed returns the DraftChangesProxy's for the draft" do608 expected_values = [proxy.new(person, transaction)]609 expect(subject.associations_removed(association)).to match_array(expected_values)610 end611 end612 end613 context 'when there is a Draft with no persisted draftable' do614 let(:new_gender) do615 FactoryBot.build(616 :gender,617 :with_persisted_draft,618 draft_transaction: transaction,619 draft_action_type: Draft::CREATE620 )621 end622 let(:subject) { proxy.new(new_gender.draft_pending_approval) }623 let(:association) { "people" }624 context 'when no additional drafts referencing the subject draft have been created' do625 it '#new_value returns an empty array' do626 expect(subject.new_value(association)).to eql([])627 end628 it '#associations_added returns an empty array' do629 expect(subject.associations_added(association)).to eql([])630 end631 it '#associations_removed returns an empty array' do632 expect(subject.associations_removed(association)).to eql([])633 end634 end635 context 'when an additional draft referencing the subject draft has been created' do636 let(:another_person) do637 FactoryBot.build(638 :person,639 :with_persisted_draft,640 draft_transaction: transaction,641 draft_action_type: Draft::CREATE,642 draft_changes: {643 "gender" => [644 nil,645 { const_type => Draft.name, const_id => new_gender.draft_pending_approval.id }646 ]647 }648 )649 end650 it "#new_value returns an the DraftChangesProxy's for the newly drafted values" do651 expected_values = [652 proxy.new(another_person.draft_pending_approval, transaction)653 ]654 expect(subject.new_value(association)).to match_array(expected_values)655 end656 it "#associations_added returns the DraftChangesProxy's for the newly drafted values" do657 expected_values = [658 proxy.new(another_person.draft_pending_approval, transaction)659 ]660 expect(subject.associations_added(association)).to match_array(expected_values)661 end662 it '#associations_removed returns an empty array' do663 expect(subject.associations_removed(association)).to eql([])664 end665 end666 context 'when a draft referencing the draftable has been created in another transaction' do667 let(:another_person) do668 FactoryBot.build(669 :person,670 :with_persisted_draft,671 draft_action_type: Draft::CREATE,672 draft_changes: {673 "gender" => [674 nil,675 { const_type => Draft.name, const_id => new_gender.draft_pending_approval.id }676 ]677 }678 )679 end680 it "#new_value returns an empty array" do681 expect(subject.new_value(association)).to match_array([])682 end683 it '#associations_added returns an empty array' do684 expect(subject.associations_added(association)).to eql([])685 end686 it '#associations_removed returns an empty array' do687 expect(subject.associations_removed(association)).to eql([])688 end689 end690 end691 end692 context 'polymorphic has_many associations' do693 context 'when there is a draftable' do694 let(:subject) { proxy.new(person, transaction) }695 let(:association) { "contact_addresses" }696 context 'when no additional drafts referencing the draftable have been created' do697 it "#new_value returns the DraftChangesProxy's for the current values" do698 expected_values = [proxy.new(contact, transaction)]699 expect(subject.new_value(association)).to match_array(expected_values)700 end701 it '#associations_added returns an empty array' do702 expect(subject.associations_added(association)).to eql([])703 end704 it '#associations_removed returns an empty array' do705 expect(subject.associations_removed(association)).to eql([])706 end707 end708 context 'when an additional draft referencing the draftable has been created' do709 let(:another_contact) do710 FactoryBot.build(711 :contact_address,712 :with_persisted_draft,713 draft_transaction: transaction,714 draft_action_type: Draft::CREATE,715 draft_changes: {716 "contactable" => [717 nil,718 { const_type => Person.name, const_id => person.id }719 ]720 }721 )722 end723 it "#new_value returns an the DraftChangesProxy's for the current values and newly drafted values" do724 expected_values = [725 proxy.new(contact, transaction),726 proxy.new(another_contact.draft_pending_approval, transaction)727 ]728 expect(subject.new_value(association)).to match_array(expected_values)729 end730 it "#associations_added returns the DraftChangesProxy's for the newly drafted values" do731 expected_values = [732 proxy.new(another_contact.draft_pending_approval, transaction)733 ]734 expect(subject.associations_added(association)).to match_array(expected_values)735 end736 it '#associations_removed returns an empty array' do737 expect(subject.associations_removed(association)).to eql([])738 end739 end740 context 'when a draft referencing the draftable has been created in another transaction' do741 let(:another_contact) do742 FactoryBot.build(743 :contact_address,744 :with_persisted_draft,745 draft_action_type: Draft::CREATE,746 draft_changes: {747 "contactable" => [748 nil,749 { const_type => Person.name, const_id => person.id }750 ]751 }752 )753 end754 it "#new_value returns the DraftChangesProxy's for the current values" do755 expected_values = [proxy.new(contact, transaction)]756 expect(subject.new_value(association)).to match_array(expected_values)757 end758 it '#associations_added returns an empty array' do759 expect(subject.associations_added(association)).to eql([])760 end761 it '#associations_removed returns an empty array' do762 expect(subject.associations_removed(association)).to eql([])763 end764 end765 context 'when a draft removing the draftable reference from the existing association has been created' do766 let!(:contact_draft) do767 FactoryBot.create(768 :draft,769 draft_transaction: transaction,770 draftable: contact,771 draft_action_type: Draft::UPDATE,772 draft_changes: {773 "contactable" => [774 { const_type => Person.name, const_id => person.id },775 nil776 ]777 }778 )779 end780 it "#new_value returns an empty array" do781 expect(subject.new_value(association)).to eql([])782 end783 it '#associations_added returns an empty array' do784 expect(subject.associations_added(association)).to eql([])785 end786 it "#associations_removed returns the DraftChangesProxy's for the draft" do787 expected_values = [proxy.new(contact, transaction)]788 expect(subject.associations_removed(association)).to match_array(expected_values)789 end790 end791 context 'when a draft deleting the associated object has been created' do792 let!(:contact_draft) do793 FactoryBot.create(794 :draft,795 draft_transaction: transaction,796 draftable: contact,797 draft_action_type: Draft::DELETE,798 draft_changes: {}799 )800 end801 it "#new_value returns an empty array" do802 expect(subject.new_value(association)).to eql([])803 end804 it '#associations_added returns an empty array' do805 expect(subject.associations_added(association)).to eql([])806 end807 it "#associations_removed returns the DraftChangesProxy's for the draft" do808 expected_values = [proxy.new(contact, transaction)]809 expect(subject.associations_removed(association)).to match_array(expected_values)810 end811 end812 end813 context 'when there is a Draft with no persisted draftable' do814 let(:new_person) do815 FactoryBot.build(816 :person,817 :with_persisted_draft,818 draft_transaction: transaction,819 draft_action_type: Draft::CREATE820 )821 end822 let(:subject) { proxy.new(new_person.draft_pending_approval) }823 let(:association) { "contact_addresses" }824 context 'when no additional drafts referencing the subject draft have been created' do825 it '#new_value returns an empty array' do826 expect(subject.new_value(association)).to eql([])827 end828 it '#associations_added returns an empty array' do829 expect(subject.associations_added(association)).to eql([])830 end831 it '#associations_removed returns an empty array' do832 expect(subject.associations_removed(association)).to eql([])833 end834 end835 context 'when an additional draft referencing the subject draft has been created' do836 let(:another_contact) do837 FactoryBot.build(838 :contact_address,839 :with_persisted_draft,840 draft_transaction: transaction,841 draft_action_type: Draft::CREATE,842 draft_changes: {843 "contactable" => [844 nil,845 { const_type => Draft.name, const_id => new_person.draft_pending_approval.id }846 ]847 }848 )849 end850 it "#new_value returns an the DraftChangesProxy's for the newly drafted values" do851 expected_values = [852 proxy.new(another_contact.draft_pending_approval, transaction)853 ]854 expect(subject.new_value(association)).to match_array(expected_values)855 end856 it "#associations_added returns the DraftChangesProxy's for the newly drafted values" do857 expected_values = [858 proxy.new(another_contact.draft_pending_approval, transaction)859 ]860 expect(subject.associations_added(association)).to match_array(expected_values)861 end862 it '#associations_removed returns an empty array' do863 expect(subject.associations_removed(association)).to eql([])864 end865 end866 context 'when a draft referencing the draftable has been created in another transaction' do867 let(:another_contact) do868 FactoryBot.build(869 :contact_address,870 :with_persisted_draft,871 draft_action_type: Draft::CREATE,872 draft_changes: {873 "contactable" => [874 nil,875 { const_type => Draft.name, const_id => new_person.draft_pending_approval.id }876 ]877 }878 )879 end880 it "#new_value returns an empty array" do881 expect(subject.new_value(association)).to match_array([])882 end883 it '#associations_added returns an empty array' do884 expect(subject.associations_added(association)).to eql([])885 end886 it '#associations_removed returns an empty array' do887 expect(subject.associations_removed(association)).to eql([])888 end889 end890 end891 end892 end893 describe '#current_to_s' do894 context 'when there is a Draft with no persisted draftable' do895 let(:new_person) do896 FactoryBot.build(897 :person,898 :with_persisted_draft,899 draft_transaction: transaction,900 draft_action_type: Draft::CREATE901 )...
event_test.rb
Source:event_test.rb
...4# Table name: eventful_events5#6# id :bigint not null, primary key7# action :string default(""), not null8# associations :jsonb9# data :jsonb10# description :string default(""), not null11# occurred_at :datetime12# resource :string default(""), not null13# created_at :datetime not null14# updated_at :datetime not null15# parent_id :bigint16# root_id :bigint17#18# Indexes19#20# index_eventful_events_on_action (action)21# index_eventful_events_on_associations (associations) USING gin22# index_eventful_events_on_data (data) USING gin23# index_eventful_events_on_parent_id (parent_id)24# index_eventful_events_on_resource (resource)25#26require "test_helper"27module Eventful28 class EventTest < ActiveSupport::TestCase29 extend Minitest::Spec::DSL30 before(:all) do31 Eventful::Event.destroy_all32 end33 describe ".by_resource" do34 it "matches one resource" do35 matching_event = FactoryBot.create(36 :event,37 resource: "echidna",38 )39 FactoryBot.create(40 :event,41 resource: "wallaby",42 )43 result = Eventful::Event.by_resource("echidna")44 assert_equal([matching_event], result)45 end46 it "matches many resources" do47 matching_event_1 = FactoryBot.create(48 :event,49 resource: "echidna",50 )51 matching_event_2 = FactoryBot.create(52 :event,53 resource: "echidna",54 )55 matching_event_3 = FactoryBot.create(56 :event,57 resource: "wallaby",58 )59 result = Eventful::Event.by_resource("echidna", "wallaby")60 assert_includes(result, matching_event_1)61 assert_includes(result, matching_event_2)62 assert_includes(result, matching_event_3)63 end64 end65 describe ".by_action" do66 it "matches one action" do67 matching_event = FactoryBot.create(68 :event,69 action: "witnessed",70 )71 FactoryBot.create(72 :event,73 action: "seen",74 )75 result = Eventful::Event.by_action("witnessed")76 assert_equal([matching_event], result)77 end78 it "matches many actions" do79 matching_event_1 = FactoryBot.create(80 :event,81 action: "witnessed",82 )83 matching_event_2 = FactoryBot.create(84 :event,85 action: "witnessed",86 )87 matching_event_3 = FactoryBot.create(88 :event,89 action: "seen",90 )91 result = Eventful::Event.by_action("witnessed", "seen")92 assert_includes(result, matching_event_1)93 assert_includes(result, matching_event_2)94 assert_includes(result, matching_event_3)95 end96 end97 describe ".by_association" do98 it "matches by integer ID" do99 matching_event = FactoryBot.create(100 :event,101 associations: {102 wombat_id: 7,103 },104 )105 FactoryBot.create(106 :event,107 associations: {108 wombat_id: 18,109 },110 )111 result = Eventful::Event.by_association(:wombat_id, 7)112 assert_equal([matching_event], result)113 end114 it "matches by UUID" do115 match_id = SecureRandom.uuid116 matching_event = FactoryBot.create(117 :event,118 associations: {119 wombat_id: match_id,120 },121 )122 FactoryBot.create(123 :event,124 associations: {125 wombat_id: SecureRandom.uuid,126 },127 )128 result = Eventful::Event.by_association(:wombat_id, match_id)129 assert_equal([matching_event], result)130 end131 end132 describe ".by_data" do133 it "queries events by data" do134 matching_event = FactoryBot.create(135 :event,136 data: { "asdf" => "jkl" },137 )138 FactoryBot.create(139 :event,140 data: { "asdf" => "asdf" },141 )142 result = Eventful::Event.by_data("asdf", "jkl")143 assert_equal([matching_event], result)144 end145 it "queries with symbolic keys" do146 matching_event = FactoryBot.create(147 :event,148 data: { "asdf" => "jkl" },149 )150 FactoryBot.create(151 :event,152 data: { "asdf" => "asdf" },153 )154 result = Eventful::Event.by_data(:asdf, "jkl")155 assert_equal([matching_event], result)156 end157 it "can be chained" do158 matching_event = FactoryBot.create(159 :event,160 data: { "asdf" => "jkl", "jkl" => "qwer" },161 )162 FactoryBot.create(163 :event,164 data: { "asdf" => "jkl" },165 )166 result = Eventful::Event.by_data(:asdf, "jkl").by_data(:jkl, "qwer")167 assert_equal([matching_event], result)168 end169 end170 describe "#data" do171 it "serializes as a hash with symbol keys" do172 e = FactoryBot.create(173 :event,174 data: {175 "foo" => "bar",176 },177 )178 assert_includes(e.data.keys, :foo)179 end180 it "defaults to empty" do181 e = Event.new182 assert_equal(e.data, {})183 end184 end185 describe "#associations" do186 it "serializes as a hash with symbol keys" do187 e = FactoryBot.create(188 :event,189 associations: {190 "wombat_id" => 3,191 },192 )193 assert_includes(e.associations.keys, :wombat_id)194 end195 it "defaults to empty" do196 e = Event.new197 assert_equal(e.associations, {})198 end199 end200 describe "#root_id" do201 it "defaults to nil" do202 e = Event.new203 assert_nil(e.root_id)204 e.valid?205 assert(e.errors[:root_id].empty?)206 end207 end208 describe "#root?" do209 it "is true with no root id" do210 event = FactoryBot.build(211 :event,...
orphaneds_spec.rb
Source:orphaneds_spec.rb
1# frozen_string_literal: true2describe Orphaneds, type: :model do3 describe 'orphaned associations errors' do4 it 'login should not cause orphaned associations' do5 FactoryBot.create(:candidate)6 expect_no_orphaned_associations7 end8 end9 describe 'orphaned associations' do10 it 'No orphaned associations' do11 FactoryBot.create(:candidate)12 expect_no_orphaned_associations13 end14 it 'orphaned associations' do15 orphans = expected_orphans16 FactoryBot.create(:candidate)17 orphaneds = Orphaneds.new18 # create orphans19 expect_orphans(orphaneds, orphans)20 end21 it 'destroy orphaned associations' do22 orphans = expected_orphans23 FactoryBot.create(:candidate)24 orphaneds = Orphaneds.new25 orphaneds.add_orphaned_table_rows26 expect_orphans(orphaneds, orphans)27 orphaneds.remove_orphaned_table_rows28 orphaneds = Orphaneds.new.add_orphaned_table_rows29 orphaned_table_rows = orphaneds.orphaned_table_rows30 orphaned_table_rows.each do |key, orphan_ids|31 expect(orphan_ids.size).to be(0), "There should be no orphaned rows for '#{key}': #{orphan_ids}"32 end33 end34 end35end36private37def expect_no_orphaned_associations38 orphaneds = Orphaneds.new39 orphaneds.add_orphaned_table_rows40 orphaned_table_rows = orphaneds.orphaned_table_rows41 orphaned_table_rows.each do |_key, orphan_ids|42 expect(orphan_ids).to be_empty43 end44end45def expected_orphans46 {47 # Candidate associations48 BaptismalCertificate: FactoryBot.create(:baptismal_certificate, skip_address_replacement: true),49 CandidateSheet: FactoryBot.create(:candidate_sheet),50 ChristianMinistry: FactoryBot.create(:christian_ministry),51 PickConfirmationName: FactoryBot.create(:pick_confirmation_name),52 RetreatVerification: FactoryBot.create(:retreat_verification),53 SponsorCovenant: FactoryBot.create(:sponsor_covenant),54 SponsorEligibility: FactoryBot.create(:sponsor_eligibility),55 # # other associations56 ScannedImage: FactoryBot.create(:scanned_image),57 Address: FactoryBot.create(:address),58 ToDo: FactoryBot.create(:to_do, confirmation_event_id: nil, candidate_event_id: nil)59 }60end61def expect_orphans(orphaneds, orphans)62 orphaneds.add_orphaned_table_rows63 orphaned_table_rows = orphaneds.orphaned_table_rows64 orphaned_table_rows.each do |key, orphan_ids|65 expect(orphan_ids.size).to be(1), "There should be only one orphaned row for '#{key}': #{orphan_ids}"66 expect(orphan_ids[0]).to be(orphans[key].id), "Id mismatch for '#{key}' orphan:#{orphan_ids[0]} expected:#{orphans[key].id}"67 end68end...
associations
Using AI Code Generation
1user = FactoryBot.create(:user)2post = FactoryBot.create(:post, user: user)3comment = FactoryBot.create(:comment, user: user, post: post)4like = FactoryBot.create(:like, user: user, post: post)5follow = FactoryBot.create(:follow, user: user, follower: user)6notification = FactoryBot.create(:notification, user: user, actor: user)7message = FactoryBot.create(:message, user: user, recipient: user)8conversation = FactoryBot.create(:conversation, sender: user, recipient: user)9chatroom = FactoryBot.create(:chatroom, user: user, follower: user)10chatroom_user = FactoryBot.create(:chatroom_user, user: user, chatroom: chatroom)11chatroom_message = FactoryBot.create(:chatroom_message, user: user, chatroom: chatroom)12chatroom_notification = FactoryBot.create(:chatroom_notification, user: user, actor: user, chatroom: chatroom)13chatroom_follow = FactoryBot.create(:chatroom_follow, user: user, follower: user, chatroom: chatroom)14chatroom_like = FactoryBot.create(:chatroom_like, user: user, follower: user, chatroom: chatroom)15chatroom_comment = FactoryBot.create(:chatroom_comment, user: user, follower: user, chatroom: chatroom)16chatroom_post = FactoryBot.create(:chatroom_post, user: user, follower: user, chatroom: chatroom)17chatroom_post_like = FactoryBot.create(:chatroom_post_like, user: user, follower: user, chatroom: chatroom, post: post)18chatroom_post_comment = FactoryBot.create(:chatroom_post_comment, user: user, follower: user, chatroom: chatroom, post: post)19chatroom_post_post = FactoryBot.create(:chatroom_post_post, user: user, follower: user, chatroom: chat
associations
Using AI Code Generation
1 name { 'John' }2 age { 18 }3 admin { false }4 name { 'Admin' }5 admin { true }6 name { 'John' }7 age { 18 }8 admin { true }9 name { 'John' }10 age { 18 }11 admin { true }12 name { 'John' }13 age { 18 }14 name { 'Admin' }15 admin { true }16 name { 'John' }17 age { 18 }18 name { 'Admin' }19 age { 18 }20 admin { true }21 name { 'John' }22 age { 18 }23 name { 'Admin' }24 age { 18 }25 admin { true }26 address { 'some address' }27 name { 'John' }28 age { 18 }29 name { 'Admin' }30 age { 18 }31 admin { true }
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!