Skip to content

Commit

Permalink
Added specs for new validations
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusf committed Jul 14, 2015
1 parent 06f6916 commit b6ff773
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 20 deletions.
1 change: 1 addition & 0 deletions spec/factories/course_condition_achievements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
class: Course::Condition::Achievement.name, aliases: [:achievement_condition] do
course
achievement
association :conditional, factory: :course_achievement
end
end
1 change: 1 addition & 0 deletions spec/factories/course_condition_levels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
class: Course::Condition::Level.name, aliases: [:level_condition] do
course
minimum_level 1
association :conditional, factory: :course_level
end
end
7 changes: 3 additions & 4 deletions spec/features/course/achievement_listing_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'rails_helper'

RSpec.describe 'Course: Achievements', type: :feature do
subject { page }
RSpec.feature 'Course: Achievements' do

let!(:instance) { create(:instance) }

Expand All @@ -20,8 +19,8 @@
visit course_achievements_path(course)
end

context 'management buttons' do
it { is_expected.to have_link(nil, href: new_course_achievement_path(course)) }
it 'management buttons' do
expect(page).to have_link(nil, href: new_course_achievement_path(course))
end

it 'shows all achievements' do
Expand Down
71 changes: 55 additions & 16 deletions spec/features/course/achievement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,61 @@
end
end

scenario 'I can create an achievement condition' do
achievement = create(:course_achievement, course: course)
visit edit_course_achievement_path(course, achievement)
condition_achievement = create(:course_achievement, course: course)
expect(page).to have_selector(:link_or_button,
I18n.t('course.condition.achievements.new.header'))
click_link I18n.t('course.condition.achievements.new.header')
expect(current_path).
to eq(new_course_achievement_condition_achievement_path(course, achievement))
find('#condition_achievement_achievement_id').
find(:css, "option[value='#{condition_achievement.id}']").
select_option
click_button I18n.t('helpers.submit.condition_achievement.create')
expect(current_path).to eq edit_course_achievement_path(course, achievement)
expect(page).to have_selector('tr.condition > td:nth-child(2)',
text: condition_achievement.title)
describe 'I can create an achievement condition' do
scenario 'if there is a valid achievement which can serve as a condition' do
achievement = create(:course_achievement, course: course)
visit edit_course_achievement_path(course, achievement)
condition_achievement = create(:course_achievement, course: course)
expect(page).to have_selector(:link,
I18n.t('course.condition.achievements.new.header'))
click_link I18n.t('course.condition.achievements.new.header')
expect(current_path).
to eq(new_course_achievement_condition_achievement_path(course, achievement))
find('#condition_achievement_achievement_id').
find(:css, "option[value='#{condition_achievement.id}']").
select_option
click_button I18n.t('helpers.submit.condition_achievement.create')
expect(current_path).to eq edit_course_achievement_path(course, achievement)
expect(page).to have_selector('tr.condition > td:nth-child(2)',
text: condition_achievement.title)
end

scenario 'unless there are no valid achievements' do
Course::Condition::Achievement.destroy_all
Course::Achievement.destroy_all
achievement = create(:course_achievement, course: course)
visit edit_course_achievement_path(course, achievement)

# The creation link won't be shown
expect(page).not_to have_selector(:link,
I18n.t('course.condition.achievements.new.header'))
end

scenario 'unless it has already been added or is the current one' do
achievement_condition, achievement, other_achievement =
create_achievement_condition
visit edit_course_achievement_path(course, achievement)
click_link I18n.t('course.condition.achievements.new.header')
expect(page).not_to have_selector("#condition_achievement_achievement_id >" \
"option[value='#{other_achievement.id}']")
expect(page).not_to have_selector("#condition_achievement_achievement_id >" \
"option[value='#{achievement.id}']")
end

scenario 'unless no achievement was selected' do
achievement = create(:course_achievement, course: course)
visit edit_course_achievement_path(course, achievement)
click_link I18n.t('course.condition.achievements.new.header')
expect(current_path).
to eq(new_course_achievement_condition_achievement_path(course, achievement))
find('#condition_achievement_achievement_id').
find(:css, "option[value='']").select_option
click_button I18n.t('helpers.submit.condition_achievement.create')
expect(current_path).
to eq(course_achievement_condition_achievements_path(course.id, achievement.id))
expect(page).
to have_text(I18n.t('course.condition.errors.none_selected'))
end
end

scenario 'I can edit an achievement condition' do
Expand Down

0 comments on commit b6ff773

Please sign in to comment.