Change Message.from_draft to Message.publish

This mmakes it more obvious that the method can only be
used on *your* messages rather than the messages of peers.
This commit is contained in:
Netscape Navigator 2020-03-13 07:42:44 -05:00
parent ff1c7cee00
commit 3c9b653f7c
2 changed files with 6 additions and 5 deletions

View File

@ -4,7 +4,7 @@ module Pigeon
class Message
attr_reader :author, :kind, :body, :signature, :depth, :prev
def self.from_draft(draft, author: KeyPair.current)
def self.publish(draft, author: KeyPair.current)
msg = self.new(author: KeyPair.current,
kind: draft.kind,
body: draft.body)
@ -35,6 +35,7 @@ module Pigeon
end
def keypair
puts "I should be using @author here!"
@keypair ||= KeyPair.current
end

View File

@ -14,7 +14,7 @@ RSpec.describe Pigeon::Message do
def create_message(params)
draft = create_draft(params)
Pigeon::Message.from_draft(draft)
Pigeon::Message.publish(draft)
end
let(:draft) do
@ -29,12 +29,12 @@ RSpec.describe Pigeon::Message do
it "discards a draft after signing" do
expect(draft.internal_id).to eq(Pigeon::Draft.current.internal_id)
Pigeon::Message.from_draft(draft)
Pigeon::Message.publish(draft)
expect(Pigeon::Draft.current).to be nil
end
it "creates a single message" do
message = Pigeon::Message.from_draft(draft)
message = Pigeon::Message.publish(draft)
expect(message.author).to eq(Pigeon::KeyPair.current)
expect(message.body).to eq(draft.body)
expect(message.depth).to eq(0)
@ -65,7 +65,7 @@ RSpec.describe Pigeon::Message do
expected_depth = n - 1
draft1 = Pigeon::Draft.create(kind: "unit_test")
draft1["description"] = "Message number #{n}"
message = Pigeon::Message.from_draft(draft1)
message = Pigeon::Message.publish(draft1)
all.push(message)
expect(message.depth).to eq(expected_depth)
if n > 1