write tests to have 100% coverage again
This commit is contained in:
parent
9d999918e5
commit
06695610dd
4 changed files with 50 additions and 29 deletions
|
|
@ -82,8 +82,6 @@ module DiasporaFederation
|
||||||
type.first.entity_name.to_sym
|
type.first.entity_name.to_sym
|
||||||
elsif type.ancestors.include?(Entity)
|
elsif type.ancestors.include?(Entity)
|
||||||
type.entity_name.to_sym
|
type.entity_name.to_sym
|
||||||
else
|
|
||||||
raise ArgumentError, "unknown type #{type} supplied"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module Validation
|
||||||
# @option params [Fixnum] :maximum maximum allowed id count
|
# @option params [Fixnum] :maximum maximum allowed id count
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
unless params.include?(:maximum) && params[:maximum].is_a?(Fixnum)
|
unless params.include?(:maximum) && params[:maximum].is_a?(Fixnum)
|
||||||
raise "A number has to be specified for :maximum"
|
raise ArgumentError, "A number has to be specified for :maximum"
|
||||||
end
|
end
|
||||||
|
|
||||||
@params = params
|
@params = params
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,19 @@ RSA
|
||||||
|
|
||||||
describe ".verify_signature" do
|
describe ".verify_signature" do
|
||||||
it "verifies correct signature" do
|
it "verifies correct signature" do
|
||||||
expect(Signing.verify_signature(hash, signature, pkey)).to be_truthy
|
expect(Signing.verify_signature(hash, signature, pkey.public_key)).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't verify wrong signature" do
|
it "doesn't verify wrong signature" do
|
||||||
expect(Signing.verify_signature(hash, "false signature==", pkey)).to be_falsy
|
expect(Signing.verify_signature(hash, "false signature==", pkey.public_key)).to be_falsy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't verify when signature is missing" do
|
||||||
|
expect(Signing.verify_signature(hash, nil, pkey.public_key)).to be_falsy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't verify when public key is missing" do
|
||||||
|
expect(Signing.verify_signature(hash, signature, nil)).to be_falsy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,20 @@ describe Validation::Rule::DiasporaIdCount do
|
||||||
}.to raise_error ArgumentError
|
}.to raise_error ArgumentError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "requires a integer as parameter" do
|
||||||
|
validator = Validation::Validator.new({})
|
||||||
|
[nil, "", 5.5].each do |val|
|
||||||
|
expect {
|
||||||
|
validator.rule(:ids, diaspora_id_count: {maximum: val})
|
||||||
|
}.to raise_error ArgumentError, "A number has to be specified for :maximum"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has an error key" do
|
||||||
|
expect(described_class.new(maximum: 5).error_key).to eq(:diaspora_id_count)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "validation" do
|
||||||
it "validates less ids" do
|
it "validates less ids" do
|
||||||
validator = Validation::Validator.new(OpenStruct.new(ids: id_str))
|
validator = Validation::Validator.new(OpenStruct.new(ids: id_str))
|
||||||
validator.rule(:ids, diaspora_id_count: {maximum: 5})
|
validator.rule(:ids, diaspora_id_count: {maximum: 5})
|
||||||
|
|
@ -40,4 +54,5 @@ describe Validation::Rule::DiasporaIdCount do
|
||||||
expect(validator).not_to be_valid
|
expect(validator).not_to be_valid
|
||||||
expect(validator.errors).to include(:ids)
|
expect(validator.errors).to include(:ids)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue