Skip to content

Commit add7fbd

Browse files
committed
Allow public access for Snippets show and index pages
1 parent 7bf2518 commit add7fbd

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

app/controllers/share/snippets_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Share::SnippetsController < ApplicationController
22
using Refinements::Emojoy
33

4-
before_action :feature_enabled!
4+
before_action :feature_enabled!, except: %i[index show]
55
before_action :authenticate_user!, only: %i[new create edit update destroy]
66

77
# GET /snippets

app/views/share/snippets/index.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<%= render Pages::Header.new(title: "Snippet Share") %>
22
<div id="snippets" class="section-content container py-gap">
3-
<div class="flex">
4-
<%= link_to "New snippet", new_share_snippet_path, class: "button primary" %>
5-
</div>
3+
<% if Flipper.enabled?(:snippets, current_user) %>
4+
<div class="flex">
5+
<%= link_to "New Snippet", new_share_snippet_path, class: "button primary" %>
6+
</div>
7+
<% end %>
68

79
<% @snippets.each do |snippet| %>
810
<%= link_to share_snippet_path(snippet), class: "block" do %>

spec/requests/share/snippets_spec.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
33
RSpec.describe "/snippets", type: :request do
44
describe "GET /index" do
55
it "renders a successful response" do
6-
Flipper.enable(:snippets, login_as_user)
7-
86
FactoryBot.create(:snippet)
97
get share_snippets_url
108
expect(response).to be_successful
119
end
10+
11+
it "does render the New Snippet button when not allowed" do
12+
get share_snippets_url
13+
14+
expect(page).to_not have_content("New Snippet")
15+
end
16+
17+
it "renders the New Snippet button when allowed" do
18+
Flipper.enable(:snippets, login_as_user)
19+
get share_snippets_url
20+
21+
expect(page).to have_content("New Snippet")
22+
end
1223
end
1324

1425
describe "GET /show" do
1526
it "renders a successful response" do
16-
Flipper.enable(:snippets, login_as_user)
17-
1827
snippet = FactoryBot.create(:snippet)
1928
get share_snippet_url(snippet)
2029
expect(response).to be_successful

spec/support/requests.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
module RequestSpecHelpers
2+
def page
3+
@page ||= Capybara.string(response.body)
4+
end
5+
end
6+
17
RSpec.configure do |config|
28
config.include Warden::Test::Helpers, type: :request
39
config.include Rails.application.routes.url_helpers, type: :request
410

511
config.before(:each, type: :request) do
612
host! "example.com"
713
end
14+
15+
config.include RequestSpecHelpers, type: :request
816
end

spec/system/snippets_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
visit share_snippets_path
1212

13-
click_link "New snippet"
13+
click_link "New Snippet"
1414

1515
fill_in "snippet[filename]", with: "app/models/blog.rb"
1616
select "Ruby", from: "Language"

0 commit comments

Comments
 (0)