38 lines
1.5 KiB
Ruby
38 lines
1.5 KiB
Ruby
shared_examples_for "an exploitable" do
|
|
Exploitable::FIELDS.each do |field|
|
|
it { is_expected.to belong_to(field).optional }
|
|
it { is_expected.to respond_to("#{field}_text") }
|
|
|
|
describe "#{field}_value" do
|
|
context "when a pre-defined value is chosen" do
|
|
it "returns the label for that value" do
|
|
exploitable = build(described_class.model_name.singular,
|
|
field => build(field, label: "My Field"),
|
|
"#{field}_text" => "Test")
|
|
expect(exploitable.public_send("#{field}_value")).to eq "My Field"
|
|
end
|
|
end
|
|
|
|
context "when 'Other' is chosen" do
|
|
it "returns the #{field} text" do
|
|
exploitable = build(described_class.model_name.singular,
|
|
field => build(field, label: "Other"),
|
|
"#{field}_text" => "Test")
|
|
expect(exploitable.public_send("#{field}_value")).to eq "Test"
|
|
end
|
|
end
|
|
|
|
if described_class.respond_to?(:contract_template)
|
|
context "when a contract template is present" do
|
|
it "returns the #{field} value from the contract template" do
|
|
contract_template = build(:contract_template, field => build(field, label: "Contract Template Field"))
|
|
exploitable = build(described_class.model_name.singular, contract_template: contract_template)
|
|
|
|
expect(exploitable.public_send("#{field}_value")).to eq "Contract Template Field"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|