-
Notifications
You must be signed in to change notification settings - Fork 23
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 #179 from JessicaML/feature_spec
Feature spec
- Loading branch information
Showing
15 changed files
with
110 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
ActiveAdmin.register Lesson do | ||
permit_params :id, :name, :description, :slug | ||
|
||
# See permitted parameters documentation: | ||
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters | ||
# | ||
# permit_params :list, :of, :attributes, :on, :model | ||
# | ||
# or | ||
# | ||
# permit_params do | ||
# permitted = [:permitted, :attributes] | ||
# permitted << :other if params[:action] == 'create' && current_user.admin? | ||
# permitted | ||
# end | ||
def to_param | ||
slug | ||
end | ||
|
||
controller do | ||
def find_resource | ||
scoped_collection.where(slug: params[:slug]).first! | ||
end | ||
end | ||
end |
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
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 |
---|---|---|
|
@@ -54,7 +54,7 @@ def destroy | |
|
||
private | ||
|
||
def set_lesson | ||
def set_lesson | ||
@lesson = Lesson.find_by(slug: params[:slug]) | ||
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 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 |
---|---|---|
@@ -1,11 +1,4 @@ | ||
FactoryBot.define do | ||
|
||
factory :lesson do | ||
name {"test"} | ||
description {"qwerty"} | ||
slug {"slug"} | ||
end | ||
|
||
factory :admin do | ||
id {2} | ||
email {"[email protected]"} | ||
|
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,12 @@ | ||
FactoryBot.define do | ||
factory :lesson do | ||
id { 1 } | ||
name { "test" } | ||
description { "Indicators" } | ||
slug { "Indicators" } | ||
|
||
trait :completed_lessons do | ||
content factory: [:completed_lessons] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Marking lessons as complete', type: :feature do | ||
before do | ||
@john = User.create!(email: "[email protected]", password: "password") | ||
@lesson = Lesson.create!(name: "Indicators", slug: "Indicators", description: "Indicators") | ||
@completed_lesson = CompletedLesson.create!(user: @john, lesson: @lesson) | ||
end | ||
|
||
scenario 'viewing the lessons' do | ||
when_i_go_to_the_home_page | ||
and_i_click_the_lessons_tab | ||
then_i_get_redirected_to_the_login_page | ||
and_i_click_the_lesson | ||
then_i_go_to_the_lesson_page | ||
end | ||
|
||
scenario 'marking a lesson as complete' do | ||
and_i_click_the_lesson | ||
then_i_go_to_the_lesson_page | ||
and_i_click_the_mark_complete_button | ||
then_i_see_that_the_lesson_has_been_marked_complete | ||
and_i_visit_the_completed_lessons_page | ||
and_the_completed_lesson_is_there | ||
end | ||
|
||
def when_i_go_to_the_home_page | ||
visit container_path | ||
end | ||
|
||
def and_i_click_the_lessons_tab | ||
click_on 'lessons' | ||
end | ||
|
||
def then_i_get_redirected_to_the_login_page | ||
fill_in 'Email', with: 'user.email' | ||
fill_in 'Password', with: 'user.password' | ||
click_on 'Login' | ||
end | ||
|
||
def and_i_click_the_lesson | ||
login_as(FactoryBot.create(:user)) | ||
visit container_path | ||
click_on 'lessons' | ||
expect(page).to have_content(@lesson.name) | ||
click_on @lesson.name | ||
end | ||
|
||
def then_i_go_to_the_lesson_page | ||
expect(page).to have_selector("input", :class =>"mark-complete") | ||
end | ||
|
||
def and_i_click_the_mark_complete_button | ||
click_button 'mark complete' | ||
end | ||
|
||
def then_i_see_that_the_lesson_has_been_marked_complete | ||
expect(page).to have_content('Lesson Complete') | ||
end | ||
|
||
def and_i_visit_the_completed_lessons_page | ||
visit completed_lessons_path | ||
end | ||
|
||
def and_the_completed_lesson_is_there | ||
expect(page).to have_content(@lesson.name) | ||
expect(page).to have_selector("a", :text =>"mark incomplete") | ||
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