Skip to content

Commit 2e26654

Browse files
committed
Properly yield self when initializing blocks with plain text emoji attributes
1 parent dc075a0 commit 2e26654

File tree

70 files changed

+157
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+157
-9
lines changed

lib/block_kit/concerns/plain_text_emoji_assignment.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ module Concerns
55
module PlainTextEmojiAssignment
66
def self.new(*attributes)
77
Module.new do
8-
define_method(:initialize) do |attrs = {}|
8+
define_method(:initialize) do |attrs = {}, &block|
99
raise ArgumentError, "expected `attributes' to be a Hash, got #{attrs.class}" unless attrs.is_a?(Hash)
1010

1111
emoji = attrs.delete(:emoji)
1212

13-
super(attrs)
13+
super(attrs, &block)
1414

1515
unless emoji.nil?
1616
attributes.each do |attribute|

spec/block_kit/base_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ def as_json(*)
2424
end
2525
end
2626

27+
it "yields self" do
28+
expect { |b| block_class.new(&b) }.to yield_with_args(block_class)
29+
end
30+
31+
it "yields self when other args are passed" do
32+
attribute = block_class.attribute_types.keys.sample
33+
34+
expect { |b| block_class.new(attribute => nil, &b) }.to yield_with_args(block_class)
35+
end
36+
2737
context "fixers" do
2838
it "allows fixing validation errors" do
2939
block = block_class.new(text: "This is a very long text that exceeds the maximum length", items: [])

spec/block_kit/blocks_spec.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
RSpec.describe BlockKit::Blocks, type: :model do
66
subject(:blocks) { described_class.new }
77

8-
describe "#initialize" do
9-
it "yields self" do
10-
described_class.new do |blocks|
11-
expect(blocks).to be_a(described_class)
12-
end
13-
end
14-
end
8+
it_behaves_like "a class that yields self on initialize"
159

1610
it_behaves_like "a block that has a DSL method",
1711
attribute: :blocks,

spec/block_kit/composition/confirmation_dialog_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
}
1414
end
1515

16+
it_behaves_like "a class that yields self on initialize"
17+
1618
describe "#as_json" do
1719
it "serializes to JSON" do
1820
expect(dialog.as_json).to eq({

spec/block_kit/composition/conversation_filter_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
}
1212
end
1313

14+
it_behaves_like "a class that yields self on initialize"
15+
1416
it "declares predicate and mutator methods for each include value" do
1517
described_class::VALID_INCLUDES.each do |value|
1618
expect(conversation_filter.public_send(:"include_#{value}?")).to be(false)

spec/block_kit/composition/dispatch_action_config_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
RSpec.describe BlockKit::Composition::DispatchActionConfig, type: :model do
66
subject(:config) { described_class.new(trigger_actions_on: ["on_enter_pressed", "on_character_entered"]) }
77

8+
it_behaves_like "a class that yields self on initialize"
9+
810
it "declares predicate and mutator methods for each trigger_actions_on value" do
911
config = described_class.new
1012

spec/block_kit/composition/input_parameter_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
}
1212
end
1313

14+
it_behaves_like "a class that yields self on initialize"
15+
1416
describe "#as_json" do
1517
it "serializes to JSON" do
1618
expect(input_parameter.as_json).to eq({

spec/block_kit/composition/mrkdwn_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
subject(:mrkdwn_block) { described_class.new(**attributes) }
77
let(:attributes) { {text: "Hello, world!"} }
88

9+
it_behaves_like "a class that yields self on initialize"
10+
911
describe "#truncate" do
1012
it "copies itself and truncates the copy's text" do
1113
mrkdwn_block.verbatim = true

spec/block_kit/composition/option_group_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
}
1212
end
1313

14+
it_behaves_like "a class that yields self on initialize"
15+
1416
it_behaves_like "a block that has a DSL method",
1517
attribute: :options,
1618
as: :option,

spec/block_kit/composition/option_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
}
1212
end
1313

14+
it_behaves_like "a class that yields self on initialize"
15+
1416
describe "#as_json" do
1517
it "serializes to JSON" do
1618
expect(option.as_json).to eq({

0 commit comments

Comments
 (0)