Skip to content

Commit

Permalink
Fixtures going down! 🤘
Browse files Browse the repository at this point in the history
  • Loading branch information
wicz committed Mar 18, 2012
1 parent 78d7880 commit 1ead73a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
11 changes: 5 additions & 6 deletions test/factories/course_memberships.rb
@@ -1,8 +1,7 @@
FactoryGirl.define do FactoryGirl.define do
factory :instructor, class: CourseMembership do factory :course_membership do
association :course, factory: 'webdev' course nil
person_github_nickname 'instructor' person_github_nickname nil
role 'Instructor' role nil
end end
end end

35 changes: 35 additions & 0 deletions test/factories/people.rb
@@ -0,0 +1,35 @@
FactoryGirl.define do
factory :person, class: OpenStruct do
name "Test"
email "test@gmail.com"
email_hash "6d2661c5a65f24c8f0bb579b6e0a0d81"
group "Visitor"
website nil
membership_date nil
github_uid "1234"
github_nickname "github_nickname"
permissions Hash[[["Clubhouse", "Administrator"],
["Community", "Administrator"],
["Liskov", "Administrator"]]]

course_membership {
FactoryGirl.create(:course_membership, course: course,
person_github_nickname: "#{github_nickname}",
role: "#{permissions['Liskov']}") if course
}
end

factory :instructor, parent: "person" do
github_nickname "instructor"
permissions Hash[[["Clubhouse", "Instructor"],
["Community", "Instructor"],
["Liskov", "Instructor"]]]
end

factory :student, parent: "person" do
github_nickname "student"
permissions Hash[[["Clubhouse", "Student"],
["Community", "Student"],
["Liskov", "Student"]]]
end
end
7 changes: 3 additions & 4 deletions test/functional/tasks_controller_test.rb
Expand Up @@ -3,13 +3,12 @@
class TasksControllerTest < ActionController::TestCase class TasksControllerTest < ActionController::TestCase


def setup def setup
cm = Factory(:instructor) @course = FactoryGirl.create(:webdev)
@course = cm.course @controller.current_person = build_person(:instructor, @course)
@controller.current_person = clubhouse_person("instructor")
end end


test "#new is not allowed to students" do test "#new is not allowed to students" do
@controller.current_person = clubhouse_person("student") @controller.current_person = build_person(:student)


get(:new, course_id: @course.id) get(:new, course_id: @course.id)
assert_redirected_to(@course) assert_redirected_to(@course)
Expand Down
10 changes: 8 additions & 2 deletions test/integration/tasks_test.rb
@@ -1,8 +1,14 @@
require "test_helper" require "test_helper"


class TasksTest < ActionDispatch::IntegrationTest class TasksTest < ActionDispatch::IntegrationTest
def setup
@course = FactoryGirl.create(:webdev)
@instructor = build_person(:instructor, @course)
@student = build_person(:student, @course)
end

test "an instructor can create a new course task" do test "an instructor can create a new course task" do
sign_in_as_instructor sign_in(@instructor)


click_link "Web Development" click_link "Web Development"
click_link "Add Task" click_link "Add Task"
Expand All @@ -12,7 +18,7 @@ class TasksTest < ActionDispatch::IntegrationTest
end end


test "a student can only view course tasks" do test "a student can only view course tasks" do
sign_in_as_student sign_in(@student)


click_link "Web Development" click_link "Web Development"
assert_not_includes(page.body, "Add Task") assert_not_includes(page.body, "Add Task")
Expand Down
14 changes: 2 additions & 12 deletions test/test_helper.rb
Expand Up @@ -5,27 +5,17 @@


Clubhouse::Client.test_mode = true Clubhouse::Client.test_mode = true


def clubhouse_person(github_nickname) def build_person(person, course = nil)
# FIXME: duplicates code from ApplicationController PersonDecorator.new(FactoryGirl.build(person, course: course))
PersonDecorator.new(Clubhouse::Client::Person.new(github_nickname))
end end


class ActiveSupport::TestCase class ActiveSupport::TestCase
end end


class ActionDispatch::IntegrationTest class ActionDispatch::IntegrationTest
include Capybara::DSL include Capybara::DSL
setup { Factory(:instructor) }
teardown { Capybara.reset_sessions! } teardown { Capybara.reset_sessions! }


def sign_in_as_instructor
sign_in clubhouse_person('instructor')
end

def sign_in_as_student
sign_in clubhouse_person('student')
end

def sign_in(person) def sign_in(person)
visit root_url visit root_url
fill_in("Name", with: person.name) fill_in("Name", with: person.name)
Expand Down

0 comments on commit 1ead73a

Please sign in to comment.