Permalink
Browse files

Fixtures going down! 🤘

  • Loading branch information...
1 parent 78d7880 commit 1ead73a14545fed54e36c74c5e79e8fe644a9207 @wicz wicz committed Mar 18, 2012
@@ -1,8 +1,7 @@
FactoryGirl.define do
- factory :instructor, class: CourseMembership do
- association :course, factory: 'webdev'
- person_github_nickname 'instructor'
- role 'Instructor'
+ factory :course_membership do
+ course nil
+ person_github_nickname nil
+ role nil
end
-end
-
+end
View
@@ -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
@@ -3,13 +3,12 @@
class TasksControllerTest < ActionController::TestCase
def setup
- cm = Factory(:instructor)
- @course = cm.course
- @controller.current_person = clubhouse_person("instructor")
+ @course = FactoryGirl.create(:webdev)
+ @controller.current_person = build_person(:instructor, @course)
end
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)
assert_redirected_to(@course)
@@ -1,8 +1,14 @@
require "test_helper"
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
- sign_in_as_instructor
+ sign_in(@instructor)
click_link "Web Development"
click_link "Add Task"
@@ -12,7 +18,7 @@ class TasksTest < ActionDispatch::IntegrationTest
end
test "a student can only view course tasks" do
- sign_in_as_student
+ sign_in(@student)
click_link "Web Development"
assert_not_includes(page.body, "Add Task")
View
@@ -5,27 +5,17 @@
Clubhouse::Client.test_mode = true
-def clubhouse_person(github_nickname)
- # FIXME: duplicates code from ApplicationController
- PersonDecorator.new(Clubhouse::Client::Person.new(github_nickname))
+def build_person(person, course = nil)
+ PersonDecorator.new(FactoryGirl.build(person, course: course))
end
class ActiveSupport::TestCase
end
class ActionDispatch::IntegrationTest
include Capybara::DSL
- setup { Factory(:instructor) }
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)
visit root_url
fill_in("Name", with: person.name)

0 comments on commit 1ead73a

Please sign in to comment.