Skip to content

Commit a9db5bc

Browse files
committed
Add view specs for snippet tweet components
1 parent af855ad commit a9db5bc

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

app/views/components/code_block/atom_aware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ def view_template
1212
end
1313

1414
def content_type?(type)
15-
helpers.headers["Content-Type"].to_s =~ %r{#{Regexp.escape(type)}}
15+
helpers&.headers&.[]("Content-Type").to_s =~ %r{#{Regexp.escape(type)}}
1616
end
1717
end

spec/factories/snippets.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
factory :snippet do
33
source { "puts \"Hello, world!\"" }
44
language { "ruby" }
5+
filename { "example.rb" }
56
author { build(:user) }
67
end
78
end

spec/support/phlex_helpers.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RSpec.configure do |config|
2+
config.before(:each, type: :view) do
3+
allow(view).to receive(:headers).and_return({"Content-Type" => "text/html"})
4+
end
5+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Share::SnippetTweets::TweetButton, type: :view do
4+
it "renders" do
5+
snippet = instance_double(Snippet, **FactoryBot.attributes_for(:snippet))
6+
render Share::SnippetTweets::TweetButton.new(snippet)
7+
8+
expect(rendered).to have_css("a[href*='x.com']")
9+
end
10+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Share::SnippetTweets::Tweet, type: :view do
4+
it "renders" do
5+
snippet = instance_double(Snippet, **FactoryBot.attributes_for(:snippet))
6+
render Share::SnippetTweets::Tweet.new(snippet)
7+
8+
expect(rendered).to have_css(".snippet-tweet")
9+
end
10+
end

0 commit comments

Comments
 (0)