write some more tests
This commit is contained in:
parent
1d8ce00bef
commit
89b068e474
6 changed files with 143 additions and 0 deletions
11
spec/models/comment_signature_spec.rb
Normal file
11
spec/models/comment_signature_spec.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe CommentSignature, type: :model do
|
||||||
|
it_behaves_like "signature data" do
|
||||||
|
let(:relayable_type) { :comment }
|
||||||
|
end
|
||||||
|
end
|
||||||
11
spec/models/like_signature_spec.rb
Normal file
11
spec/models/like_signature_spec.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe LikeSignature, type: :model do
|
||||||
|
it_behaves_like "signature data" do
|
||||||
|
let(:relayable_type) { :like }
|
||||||
|
end
|
||||||
|
end
|
||||||
11
spec/models/poll_participation_signature_spec.rb
Normal file
11
spec/models/poll_participation_signature_spec.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe PollParticipationSignature, type: :model do
|
||||||
|
it_behaves_like "signature data" do
|
||||||
|
let(:relayable_type) { :poll_participation }
|
||||||
|
end
|
||||||
|
end
|
||||||
25
spec/models/signature_order_spec.rb
Normal file
25
spec/models/signature_order_spec.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe SignatureOrder, type: :model do
|
||||||
|
context "validation" do
|
||||||
|
it "requires an order" do
|
||||||
|
order = SignatureOrder.new
|
||||||
|
expect(order).not_to be_valid
|
||||||
|
|
||||||
|
order.order = "author guid"
|
||||||
|
expect(order).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't allow the same order twice" do
|
||||||
|
first = SignatureOrder.create!(order: "author guid")
|
||||||
|
expect(first).to be_valid
|
||||||
|
|
||||||
|
second = SignatureOrder.new(order: first.order)
|
||||||
|
expect(second).not_to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -68,4 +68,32 @@ shared_examples_for "it is relayable" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#signature" do
|
||||||
|
let(:signature_class) { described_class.reflect_on_association(:signature).klass }
|
||||||
|
|
||||||
|
before do
|
||||||
|
remote_object_on_local_parent.signature = signature_class.new(
|
||||||
|
author_signature: "signature",
|
||||||
|
additional_data: {"new_property" => "some text"},
|
||||||
|
signature_order: FactoryGirl.create(:signature_order)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the signature data" do
|
||||||
|
signature = described_class.find(remote_object_on_local_parent.id).signature
|
||||||
|
expect(signature).not_to be_nil
|
||||||
|
expect(signature.author_signature).to eq("signature")
|
||||||
|
expect(signature.additional_data).to eq("new_property" => "some text")
|
||||||
|
expect(signature.order).to eq(%w(guid parent_guid text author))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "deletes the signature when destroying the relayable" do
|
||||||
|
id = remote_object_on_local_parent.id
|
||||||
|
remote_object_on_local_parent.destroy!
|
||||||
|
|
||||||
|
signature = signature_class.find_by(signature_class.primary_key => id)
|
||||||
|
expect(signature).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
57
spec/shared_behaviors/signature.rb
Normal file
57
spec/shared_behaviors/signature.rb
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
shared_examples_for "signature data" do
|
||||||
|
let(:relayable) { FactoryGirl.create(relayable_type) }
|
||||||
|
let(:signature) {
|
||||||
|
described_class.new(
|
||||||
|
relayable_type => relayable,
|
||||||
|
:author_signature => "signature",
|
||||||
|
:additional_data => {"additional_data" => "some data"},
|
||||||
|
:signature_order => SignatureOrder.new(order: "author guid parent_guid")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
describe "#order" do
|
||||||
|
it "it returns the order as array" do
|
||||||
|
expect(signature.order).to eq(%w(author guid parent_guid))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#additional_data" do
|
||||||
|
it "is stored as hash" do
|
||||||
|
signature.save
|
||||||
|
|
||||||
|
entity = described_class.reflect_on_association(relayable_type).klass.find(relayable.id)
|
||||||
|
expect(entity.signature.additional_data).to eq("additional_data" => "some data")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can be missing" do
|
||||||
|
signature.additional_data = nil
|
||||||
|
signature.save
|
||||||
|
|
||||||
|
entity = described_class.reflect_on_association(relayable_type).klass.find(relayable.id)
|
||||||
|
expect(entity.signature.additional_data).to eq({})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "validation" do
|
||||||
|
it "is valid" do
|
||||||
|
expect(signature).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "requires a linked relayable" do
|
||||||
|
signature.public_send("#{relayable_type}=", nil)
|
||||||
|
expect(signature).not_to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "requires a signature_order" do
|
||||||
|
signature.signature_order = nil
|
||||||
|
expect(signature).not_to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "requires a author_signature" do
|
||||||
|
signature.author_signature = nil
|
||||||
|
expect(signature).not_to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue