Files
old-holivud2/spec/support/shared_examples_for_an_approvable.rb
2020-08-24 15:52:23 +02:00

48 lines
1.6 KiB
Ruby

shared_examples_for "an approvable" do
it { is_expected.to respond_to(:approved_by_user_signature) }
describe "#approve_by" do
before do
allow(BigMediaTime).to receive(:time_zone_now).and_return(1.week.ago)
end
it "stores info about the approving user" do
user = double(full_name: "Jane Doe", email: "jane.doe@test.com")
subject.approve_by(user)
expect(subject.approved_by_user_name).to eq "Jane Doe"
expect(subject.approved_by_user_email).to eq "jane.doe@test.com"
expect(subject.approved_at).to eq BigMediaTime.time_zone_now
end
context "when approval has already been given" do
it "does not change the existing info" do
user1 = double(full_name: "Jane Doe", email: "jane.doe@test.com")
subject.approve_by(user1)
expect(subject.approved_by_user_name).to eq "Jane Doe"
expect(subject.approved_by_user_email).to eq "jane.doe@test.com"
expect(subject.approved_at).to eq BigMediaTime.time_zone_now
user2 = double(full_name: "John Doe", email: "john.doe@test.com")
subject.approve_by(user2)
expect(subject.approved_by_user_name).to eq "Jane Doe"
expect(subject.approved_by_user_email).to eq "jane.doe@test.com"
expect(subject.approved_at).to eq BigMediaTime.time_zone_now
end
end
end
describe "#approved?" do
it "indicates whether or not it has been approved" do
subject.approved_at = nil
expect(subject).not_to be_approved
subject.approved_at = 1.week.ago
expect(subject).to be_approved
end
end
end