Skip to content

Commit

Permalink
Merge pull request #179 from JessicaML/feature_spec
Browse files Browse the repository at this point in the history
Feature spec
  • Loading branch information
JessicaML authored Dec 16, 2020
2 parents 8a0f9f6 + 6dfff17 commit f3aad1d
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 34 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'launchy'
gem 'selenium-webdriver'
gem 'rspec-rails', '~> 3.5'
gem 'rails-controller-testing'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ GEM
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
launchy (2.5.0)
addressable (~> 2.7)
libv8 (7.3.492.27.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand Down Expand Up @@ -341,6 +343,7 @@ DEPENDENCIES
figaro
inherited_resources!
jbuilder (~> 2.5)
launchy
libv8
listen (>= 3.0.5, < 3.2)
mini_racer (~> 0.2.9)
Expand Down
20 changes: 8 additions & 12 deletions app/admin/lessons.rb
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 removed app/controllers/concerns/.keep
Empty file.
4 changes: 0 additions & 4 deletions app/controllers/container_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@

class ContainerController < ApplicationController
layout "application"

def index
@container_props = { name: "Stranger" }
end
end
2 changes: 1 addition & 1 deletion app/controllers/lessons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def destroy

private

def set_lesson
def set_lesson
@lesson = Lesson.find_by(slug: params[:slug])
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const FeaturedLessons = () => (
<h1>Featured Lessons</h1>
</div>
<div className="links">
<a href="lessons/1">
<a href="lessons/Indicators">
<h1>Indicators</h1>
</a>
<a href="lessons/3">
<a href="lessons/CellsTissuesOrgans">
<h1>Cells, Tissues, Organs</h1>
</a>
<a href="lessons/2">
<a href="lessons/DNA">
<h1>DNA</h1>
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ exports[`Container renders correctly when there are no items 1`] = `
className="links"
>
<a
href="lessons/1"
href="lessons/Indicators"
>
<h1>
Indicators
</h1>
</a>
<a
href="lessons/3"
href="lessons/CellsTissuesOrgans"
>
<h1>
Cells, Tissues, Organs
</h1>
</a>
<a
href="lessons/2"
href="lessons/DNA"
>
<h1>
DNA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ exports[`FeaturedLessons renders correctly when there are no items 1`] = `
className="links"
>
<a
href="lessons/1"
href="lessons/Indicators"
>
<h1>
Indicators
</h1>
</a>
<a
href="lessons/3"
href="lessons/CellsTissuesOrgans"
>
<h1>
Cells, Tissues, Organs
</h1>
</a>
<a
href="lessons/2"
href="lessons/DNA"
>
<h1>
DNA
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
end

devise_for :admin_users, ActiveAdmin::Devise.config

namespace :admin do
resources :lessons, param: :slug
end

ActiveAdmin.routes(self)

resources :users do
Expand Down
1 change: 0 additions & 1 deletion spec/controller/completed_lessons_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
put :togglelesson, params: {
id: completed_lesson, completed: false
}
binding.pry
completed_lesson.reload
expect(completed_lesson.completed).to eq(false)
expect(response).to redirect_to(lesson_url(slug: completed_lesson.lesson.slug, anchor: 'mark-complete'))
Expand Down
7 changes: 0 additions & 7 deletions spec/factories/devise.rb
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]"}
Expand Down
12 changes: 12 additions & 0 deletions spec/factories/lessons.rb
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
69 changes: 69 additions & 0 deletions spec/features/marking_lessons_as_complete_spec.rb
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
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

config.fixture_path = "#{::Rails.root}/spec/fixtures"

config.include Warden::Test::Helpers

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
Expand Down

0 comments on commit f3aad1d

Please sign in to comment.