-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from RileyManda/feature/recipe-tests-authoriza…
…tion Feature/recipe tests authorization
- Loading branch information
Showing
14 changed files
with
230 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Ability | ||
include CanCan::Ability | ||
|
||
def initialize(user) | ||
user ||= User.new | ||
can :manage, Recipe, user_id: user.id | ||
# Define abilities for the user here. For example: | ||
# | ||
# return unless user.present? | ||
# can :read, :all | ||
# return unless user.admin? | ||
# can :manage, :all | ||
# | ||
# The first argument to `can` is the action you are giving the user | ||
# permission to do. | ||
# If you pass :manage it will apply to every action. Other common actions | ||
# here are :read, :create, :update and :destroy. | ||
# | ||
# The second argument is the resource the user can perform the action on. | ||
# If you pass :all it will apply to every resource. Otherwise pass a Ruby | ||
# class of the resource. | ||
# | ||
# The third argument is an optional hash of conditions to further filter the | ||
# objects. | ||
# For example, here the user can only update published articles. | ||
# | ||
# can :update, Article, published: true | ||
# | ||
# See the wiki for details: | ||
# https://github.com/CanCanCommunity/cancancan/blob/develop/docs/define_check_abilities.md | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'Public Recipes Page', type: :feature do | ||
scenario 'all users can see public recipes' do | ||
user = create(:user) | ||
login_as(user, scope: :user) | ||
recipe = create(:recipe, user:) | ||
visit public_recipes_path | ||
expect(page).to have_content(recipe.name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'Recipe#index Page', type: :feature do | ||
scenario 'authorized user can add a new recipe' do | ||
user = create(:user) | ||
login_as(user, scope: :user) | ||
visit recipe_index_path | ||
click_button('Add Recipe') | ||
expect(page).to have_current_path(new_recipe_path) | ||
end | ||
|
||
scenario 'user can remove their recipe' do | ||
user = create(:user) | ||
login_as(user, scope: :user) | ||
visit recipe_index_path | ||
expect(page).not_to have_button('Remove', exact: true) | ||
end | ||
|
||
scenario 'user can add a new recipe' do | ||
user = create(:user) | ||
login_as(user, scope: :user) | ||
visit recipe_index_path | ||
expect(page).to have_button('Add Recipe', exact: true) | ||
end | ||
|
||
scenario 'user can view their own private and public recipes' do | ||
user = create(:user) | ||
login_as(user, scope: :user) | ||
recipe = create(:recipe, user:) | ||
visit recipe_index_path | ||
expect(page).to have_content(recipe.name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,59 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Recipe, type: :model do | ||
describe Recipe, type: :model do | ||
it 'is valid with valid attributes' do | ||
user = User.create(name: 'johndoes', email: 'john@email.com', password: '123456') | ||
recipe = Recipe.new( | ||
name: 'Sample Recipe', | ||
preparation_time: 30, | ||
cooking_time: 60, | ||
description: 'Recipe description', | ||
public: true, | ||
user: | ||
) | ||
expect(recipe).to be_valid | ||
end | ||
|
||
it 'is not valid without a name' do | ||
recipe = Recipe.new(name: nil) | ||
expect(recipe).not_to be_valid | ||
end | ||
|
||
it 'is not valid without a user' do | ||
recipe = Recipe.new( | ||
name: 'MyRecipe', | ||
preparation_time: 30, | ||
cooking_time: 60, | ||
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', | ||
public: true | ||
) | ||
expect(recipe).not_to be_valid | ||
end | ||
it 'is not valid with a negative preparation time' do | ||
user = User.create(name: 'johndoes', email: 'john@email.com', password: '123456') | ||
recipe = Recipe.new( | ||
name: 'Sample Recipe', | ||
preparation_time: -5, | ||
cooking_time: 60, | ||
description: 'Recipe description', | ||
public: true, | ||
user: | ||
) | ||
expect(recipe).not_to be_valid | ||
end | ||
|
||
it 'is not valid with a negative cooking time' do | ||
user = User.create(name: 'johndoes', email: 'john@email.com', password: '123456') | ||
recipe = Recipe.new( | ||
name: 'Sample Recipe', | ||
preparation_time: 30, | ||
cooking_time: -10, | ||
description: 'Recipe description', | ||
public: true, | ||
user: | ||
) | ||
expect(recipe).not_to be_valid | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.