File: association_spec.rb

package info (click to toggle)
ruby-factory-bot 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,372 kB
  • sloc: ruby: 7,827; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 1,143 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
describe FactoryBot::Attribute::Association do
  let(:name) { :author }
  let(:factory) { :user }
  let(:overrides) { {first_name: "John"} }
  let(:association) { double("association") }

  subject { FactoryBot::Attribute::Association.new(name, factory, overrides) }

  before do
    # Define an '#association' instance method allowing it to be mocked.
    # Usually this is determined via '#method_missing'
    missing_methods = Module.new {
      def association(*args)
      end
    }
    subject.extend(missing_methods)

    allow(subject)
      .to receive(:association).with(any_args).and_return association
  end

  it { should be_association }
  its(:name) { should eq name }

  it "builds the association when calling the proc" do
    expect(subject.to_proc.call).to eq association
  end

  it "builds the association when calling the proc" do
    subject.to_proc.call
    expect(subject).to have_received(:association).with(factory, overrides)
  end
end

describe FactoryBot::Attribute::Association, "with a string name" do
  subject { FactoryBot::Attribute::Association.new("name", :user, {}) }
  its(:name) { should eq :name }
end