mirror of https://github.com/Calamitous/iris.git
Fix bug preventing reply when parent hash starts with a digit
This commit is contained in:
parent
b6e24e7afd
commit
ae7b0e5fb8
23
iris.rb
23
iris.rb
|
@ -50,6 +50,7 @@ require 'digest'
|
|||
require 'json'
|
||||
require 'etc'
|
||||
require 'readline'
|
||||
# require 'pry' # Only needed for debugging
|
||||
|
||||
class String
|
||||
def wrapped(width = Display::WIDTH)
|
||||
|
@ -118,17 +119,15 @@ class Corpus
|
|||
indexes.map{ |idx| all[idx] }
|
||||
end
|
||||
|
||||
def self.find_topic(topic_lookup)
|
||||
def self.find_topic_by_id(topic_lookup)
|
||||
return nil unless topic_lookup
|
||||
if topic_lookup.to_i == 0
|
||||
# This must be a hash, handle appropriately
|
||||
msg = find_message_by_hash(topic_lookup)
|
||||
msg
|
||||
else
|
||||
# This must be an index, handle appropriately
|
||||
index = topic_lookup.to_i - 1
|
||||
return topics[index] if index >= 0 && index < topics.length
|
||||
end
|
||||
index = topic_lookup.to_i - 1
|
||||
topics[index] if index >= 0 && index < topics.length
|
||||
end
|
||||
|
||||
def self.find_topic_by_hash(topic_lookup)
|
||||
return nil unless topic_lookup
|
||||
find_message_by_hash(topic_lookup)
|
||||
end
|
||||
|
||||
def self.read_hashes
|
||||
|
@ -449,7 +448,7 @@ class Interface
|
|||
return
|
||||
end
|
||||
|
||||
if parent = Corpus.find_topic(topic_id)
|
||||
if parent = Corpus.find_topic_by_id(topic_id)
|
||||
@reply_topic = parent.hash
|
||||
else
|
||||
Display.say "Could not reply; unable to find a topic with ID '#{topic_id}'"
|
||||
|
@ -458,7 +457,7 @@ class Interface
|
|||
|
||||
@mode = :replying
|
||||
@text_buffer = ''
|
||||
title = Corpus.find_topic(parent.hash).truncated_message(Display::WIDTH - 26)
|
||||
title = Corpus.find_topic_by_hash(parent.hash).truncated_message(Display::WIDTH - 26)
|
||||
Display.say
|
||||
Display.say "Writing a reply to topic '#{title}'"
|
||||
Display.say 'Type a period on a line by itself to end message.'
|
||||
|
|
20
iris_test.rb
20
iris_test.rb
|
@ -102,14 +102,9 @@ describe Corpus do
|
|||
it 'returns the messages associated with the parent hash'
|
||||
end
|
||||
|
||||
describe '.find_topic' do
|
||||
describe '.find_topic_by_id' do
|
||||
it 'returns nil if a nil is passed in' do
|
||||
Corpus.find_topic(nil).must_equal nil
|
||||
end
|
||||
|
||||
describe 'when a hash string is passed in' do
|
||||
it 'returns nil if the topic is not found'
|
||||
it 'returns the associated topic'
|
||||
Corpus.find_topic_by_id(nil).must_equal nil
|
||||
end
|
||||
|
||||
describe 'when an index string is passed in' do
|
||||
|
@ -117,6 +112,17 @@ describe Corpus do
|
|||
it 'returns the associated topic'
|
||||
end
|
||||
end
|
||||
|
||||
describe '.find_topic_by_hash' do
|
||||
it 'returns nil if a nil is passed in' do
|
||||
Corpus.find_topic_by_hash(nil).must_equal nil
|
||||
end
|
||||
|
||||
describe 'when a hash string is passed in' do
|
||||
it 'returns nil if the topic is not found'
|
||||
it 'returns the associated topic'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe IrisFile do
|
||||
|
|
Loading…
Reference in New Issue