Comment out old code, add tests
This commit is contained in:
parent
caf580951e
commit
f76ee47b7a
|
@ -4,6 +4,7 @@ module Pigeon
|
|||
class Message
|
||||
NAME_OF_DRAFT = "HEAD.draft"
|
||||
OUTBOX_PATH = File.join(".pigeon", "user")
|
||||
EMPTY_MESSAGE = "NONE"
|
||||
|
||||
attr_reader :author, :kind, :prev, :body, :depth, :signature
|
||||
|
||||
|
@ -20,7 +21,7 @@ module Pigeon
|
|||
@prev = prev
|
||||
@body = body
|
||||
@depth = calculate_depth
|
||||
@prev = previous_message ? previous_message.signature : "NONE"
|
||||
@prev = previous_message ? previous_message.signature : EMPTY_MESSAGE
|
||||
end
|
||||
|
||||
def self.current
|
||||
|
@ -61,39 +62,40 @@ module Pigeon
|
|||
private
|
||||
|
||||
def calculate_signature
|
||||
template = Template.new(self)
|
||||
string = template.render_without_signature
|
||||
KeyPair.current.sign(string)
|
||||
# template = Template.new(self)
|
||||
# string = template.render_without_signature
|
||||
# KeyPair.current.sign(string)
|
||||
end
|
||||
|
||||
def path_to_message_number(n)
|
||||
File.join(".pigeon", "user", "#{n.to_s.rjust(7, "0")}.pigeon")
|
||||
# File.join(".pigeon", "user", "#{n.to_s.rjust(7, "0")}.pigeon")
|
||||
end
|
||||
|
||||
def previous_message
|
||||
if @depth.nil?
|
||||
raise "Could not load @depth"
|
||||
end
|
||||
# if @depth.nil?
|
||||
# raise "Could not load @depth"
|
||||
# end
|
||||
|
||||
if @previous_message
|
||||
return @previous_message
|
||||
end
|
||||
# if @previous_message
|
||||
# return @previous_message
|
||||
# end
|
||||
|
||||
if @depth == 1
|
||||
return @previous_message = nil
|
||||
end
|
||||
# if @depth == 1
|
||||
# return @previous_message = nil
|
||||
# end
|
||||
|
||||
path = path_to_message_number(@depth - 1)
|
||||
@previous_message = Marshal.load(File.read(path))
|
||||
# path = path_to_message_number(@depth - 1)
|
||||
# @previous_message = Marshal.load(File.read(path))
|
||||
end
|
||||
|
||||
def calculate_depth
|
||||
Dir[OUTBOX_PATH].count
|
||||
# Dir[OUTBOX_PATH].count
|
||||
0
|
||||
end
|
||||
|
||||
def message_id # I need this to calculate `prev`.
|
||||
raise "NO!" unless @signature && !@signature.downcase.include?("draft")
|
||||
Digest::SHA256.digest(self.render)
|
||||
# raise "NO!" unless @signature && !@signature.downcase.include?("draft")
|
||||
# Digest::SHA256.digest(self.render)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,41 +40,41 @@ echo "listing all peers:"
|
|||
echo "Making a new `scratch_pad` log entry"
|
||||
./pigeon-cli message create scratch_pad
|
||||
|
||||
echo "Appending values..."
|
||||
# echo "Appending values..."
|
||||
|
||||
echo "...string via pipe"
|
||||
# echo "...string via pipe"
|
||||
|
||||
echo "my_value" | ./pigeon-cli message append key1
|
||||
# echo "my_value" | ./pigeon-cli message append key1
|
||||
|
||||
echo "...string with no quotes"
|
||||
./pigeon-cli message append key2 my_value2
|
||||
# echo "...string with no quotes"
|
||||
# ./pigeon-cli message append key2 my_value2
|
||||
|
||||
echo "...string with quotes"
|
||||
./pigeon-cli message append key3 "my_value3"
|
||||
# echo "...string with quotes"
|
||||
# ./pigeon-cli message append key3 "my_value3"
|
||||
|
||||
echo "...message ID"
|
||||
./pigeon-cli message append key4 \%jvKh9yoiEJaePzoWCF1nnqpIlPgTk9FHEtqczQbvzGM=.sha256
|
||||
# echo "...message ID"
|
||||
# ./pigeon-cli message append key4 \%jvKh9yoiEJaePzoWCF1nnqpIlPgTk9FHEtqczQbvzGM=.sha256
|
||||
|
||||
echo "...blob"
|
||||
./pigeon-cli message append key5 \&29f3933302c49c60841d7620886ce54afc68630242aee6ff683926d2465e6ca3.sha256
|
||||
# echo "...blob"
|
||||
# ./pigeon-cli message append key5 \&29f3933302c49c60841d7620886ce54afc68630242aee6ff683926d2465e6ca3.sha256
|
||||
|
||||
echo "...identity"
|
||||
./pigeon-cli message append key6 \@galdahnB3L2DE2cTU0Me54IpIUKVEgKmBwvZVtWJccg=.ed25519
|
||||
# echo "...identity"
|
||||
# ./pigeon-cli message append key6 \@galdahnB3L2DE2cTU0Me54IpIUKVEgKmBwvZVtWJccg=.ed25519
|
||||
|
||||
echo "== show draft message"
|
||||
./pigeon-cli message show
|
||||
# echo "== show draft message"
|
||||
# ./pigeon-cli message show
|
||||
|
||||
echo "== sign (publish, save, commit, etc) draft message"
|
||||
./pigeon-cli message sign
|
||||
# echo "== sign (publish, save, commit, etc) draft message"
|
||||
# ./pigeon-cli message sign
|
||||
|
||||
echo "=== add a second message to the db"
|
||||
./pigeon-cli message create second_test
|
||||
# echo "=== add a second message to the db"
|
||||
# ./pigeon-cli message create second_test
|
||||
|
||||
echo "=== append hello:'world' to message:"
|
||||
./pigeon-cli message append hello "world"
|
||||
# echo "=== append hello:'world' to message:"
|
||||
# ./pigeon-cli message append hello "world"
|
||||
|
||||
echo "=== Sign message #2"
|
||||
./pigeon-cli message sign
|
||||
# echo "=== Sign message #2"
|
||||
# ./pigeon-cli message sign
|
||||
|
||||
echo "=== getting status:"
|
||||
./pigeon-cli status
|
||||
# echo "=== getting status:"
|
||||
# ./pigeon-cli status
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
require "spec_helper"
|
||||
|
||||
RSpec.describe Pigeon::Message do
|
||||
it "??"
|
||||
it "creates a new message" do
|
||||
message = Pigeon::Message.create(kind: "unit_test")
|
||||
expect(message.author).to eq(Pigeon::KeyPair.current.public_key)
|
||||
expect(message.kind).to eq("unit_test")
|
||||
expect(message.body).to eq({})
|
||||
expect(message.depth).to eq(0)
|
||||
expect(message.prev).to eq(Pigeon::Message::EMPTY_MESSAGE)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue