diaspora_federation/spec/support/helper_methods.rb
Benjamin Neff 40919b4c69
Create change_time helper method
Time#change is an activesupport feature

Also: Use seconds instead of Numeric#minute and Numeric#hour
2017-04-05 00:36:53 +02:00

37 lines
1.1 KiB
Ruby

# default users
def alice
@alice ||= Fabricate(:user, diaspora_id: "alice@localhost:3000")
end
def bob
@bob ||= Fabricate(:user, diaspora_id: "bob@localhost:3000")
end
# callback expectation helper
def expect_callback(*opts)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(*opts)
end
# signature methods
def add_signatures(hash, klass=described_class)
properties = klass.new(hash).send(:enriched_properties)
hash[:author_signature] = properties[:author_signature]
hash[:parent_author_signature] = properties[:parent_author_signature]
end
def sign_with_key(privkey, signature_data)
Base64.strict_encode64(privkey.sign(OpenSSL::Digest::SHA256.new, signature_data))
end
def verify_signature(pubkey, signature, signed_string)
pubkey.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(signature), signed_string)
end
# time helper
def change_time(time, options={})
new_hour = options.fetch(:hour, time.hour)
new_min = options.fetch(:min, options[:hour] ? 0 : time.min)
new_sec = options.fetch(:sec, options[:hour] || options[:min] ? 0 : time.sec)
::Time.utc(time.year, time.month, time.day, new_hour, new_min, new_sec)
end