Skip to content

Commit

Permalink
better msg
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Sep 9, 2023
1 parent 3f943dc commit c9e9ad6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mailanes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@
params[:d] ? "It was the reaction to [this](http://www.mailanes.com/delivery?id=#{params[:d]})." : '',
"There are #{list.recipients.active_count} active subscribers in the list still,",
"out of #{list.recipients.count} total.",
"This is what we know about the recipient:\n\n```\n#{recipient.yaml.to_yaml}\n```"
recipient.yaml.empty? ? '' : "This is what we know about the recipient:\n\n```\n#{recipient.yaml.to_yaml}\n```"
)
recipient.post_event("Unsubscribed#{@locals[:user] ? " by @#{current_user}" : ''}.")
else
Expand Down
4 changes: 4 additions & 0 deletions objects/yaml_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def initialize(text)
@text = text
end

def empty?
load.empty?
end

def load
hash = YAML.safe_load(@text)
hash = {} unless hash.is_a?(Hash)
Expand Down
6 changes: 6 additions & 0 deletions test/test_yaml_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def test_loads_valid_yaml
assert_equal(25, yaml['age'])
end

def test_checks_emptiness
assert(YamlDoc.new('').empty?)
assert(YamlDoc.new("---\n").empty?)
assert(!YamlDoc.new("a: b\n").empty?)
end

def test_saves_valid_yaml
text = YamlDoc.new("title: \"Test\"\nage: 25").save
assert(text.include?('title: Test'), text)
Expand Down

0 comments on commit c9e9ad6

Please sign in to comment.