Skip to content

Instantly share code, notes, and snippets.

@walidvb
Created June 11, 2014 12:46
Show Gist options
  • Save walidvb/e87e6a94a21286c3d95c to your computer and use it in GitHub Desktop.
Save walidvb/e87e6a94a21286c3d95c to your computer and use it in GitHub Desktop.
class BooksController < ApplicationController
before_filter do |controller|
#binding.pry
if(Book.find_by_slug(params[:id]).published? && current_user.is_admin?)
flash[:warning] = "Please login as admin to view this page"
redirect_to root_path
end
end
def show
@book = Book.find_by_slug(params[:id]) or raise "No such book '#{params[:id]}'"
@comments = @book.comments.reversed_nested_set.with_state([:draft, :published])
end
def subscribed
@book = Book.find_by_slug(params[:id]) or raise "No such book '#{params[:id]}'"
end
end
Scenario: Book is private
Given there is a published book
And the book is private
When I visit the book
Then I should be on the home page
When(/^I visit the book$/) do
# no online reader for now
visit book_path(Book.first)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment