diff --git a/Gemfile b/Gemfile index 9d6651cdd23..f2034a91999 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem 'dynamic_form' gem 'edavis10-ruby-web-search' gem 'engtagger' gem 'expertiza-authlogic', github: 'expertiza/authlogic', :require => 'authlogic' +gem "factory_girl_rails","~> 4.0" gem 'fastercsv' gem 'ffi-aspell' gem 'font-awesome-rails' @@ -55,7 +56,7 @@ gem 'uglifier' gem 'will_paginate' gem 'zip-zip' gem 'react-rails', '~> 1.0' - +gem 'rspec-rails', '~> 3.0' group :development do gem 'daemons' gem 'pry' @@ -72,7 +73,7 @@ group :test do gem 'guard-rails' gem 'guard-rspec' gem 'launchy' - gem 'rspec-rails' + #gem 'rspec-rails' gem 'shoulda' gem 'test-unit' end diff --git a/Gemfile.lock b/Gemfile.lock index 58f152b5757..1b6f92eb752 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -115,6 +115,11 @@ GEM erubis (2.7.0) eventmachine (1.0.8) execjs (2.6.0) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) + railties (>= 3.0.0) faraday (0.9.1) multipart-post (>= 1.2, < 3) fastercsv (1.5.5) @@ -423,6 +428,7 @@ DEPENDENCIES edavis10-ruby-web-search engtagger expertiza-authlogic! + factory_girl_rails (~> 4.0) fastercsv ffi-aspell font-awesome-rails @@ -458,7 +464,7 @@ DEPENDENCIES react-rails (~> 1.0) rgl rjb - rspec-rails + rspec-rails (~> 3.0) rubyzip rwordnet (= 0.1.3) sass-rails (= 5.0.3) diff --git a/app/models/assignment.rb b/app/models/assignment.rb index c7feab73e02..b6563ac27a4 100644 --- a/app/models/assignment.rb +++ b/app/models/assignment.rb @@ -130,6 +130,7 @@ def candidate_topics_to_review(reviewer) #This method is only for the assignments without topics def candidate_assignment_teams_to_review(reviewer) # the contributors are AssignmentTeam objects + contributor_set = Array.new(contributors) # Reject contributors that have no submissions @@ -335,7 +336,7 @@ def contributor_to_review(reviewer, topic) def contributors #ACS Contributors are just teams, so removed check to see if it is a team assignment @contributors ||= teams #ACS - end + end def assign_metareviewer_dynamically(meta_reviewer) # The following method raises an exception if not successful which diff --git a/spec/factories.rb b/spec/factories.rb new file mode 100644 index 00000000000..3e57d3e67b8 --- /dev/null +++ b/spec/factories.rb @@ -0,0 +1,55 @@ +require 'factory_girl_rails' + +FactoryGirl.define do + + #instructor for assignment + factory :user do + sequence(:name) { |n| "NewName #{n}" } + fullname {"test_user"} + email {"sjolly@ncsu.edu"} + parent_id =1 + is_new_user=true + end + + + # Factory for Assignment with name + factory :assignment do + #name {'OSS'} + sequence(:name) { |n| "OS #{n}" } + submitter_count {3} + is_coding_assignment {true} + microtask {true} + review_assignment_strategy {'Auto-Selected'} + association :instructor, factory: :user + association :wiki_type, factory: :wiki_type + end + + # Factory for Assignment without name + factory :assignment_without_name, class: Assignment do + name {} + submitter_count {3} + is_coding_assignment {true} + microtask {true} + review_assignment_strategy {'Auto-Selected'} + association :instructor, factory: :user + association :wiki_type, factory: :wiki_type + end + + # Factory for wiki type + factory :wiki_type do + name {'wiki_1a'} + end + + # Factory for Assignment Team + + factory :assignmentTeam, class: AssignmentTeam do + + end + + factory :signed_up_topic, class: SignUpTopic do + topic_name {'TestApplication'} + topic_identifier {'A1234B1234'} + #association :assignment, factory: :assignment + assignment + end +end diff --git a/spec/models/assignment_spec.rb b/spec/models/assignment_spec.rb new file mode 100644 index 00000000000..27ff214a43a --- /dev/null +++ b/spec/models/assignment_spec.rb @@ -0,0 +1,107 @@ +require 'rails_helper' +require 'spec_helper' + +describe "validations" do + it "assignment should exist" do + FactoryGirl.create(:assignment).should be_valid + end + + it "assignment without name should not exist" do + FactoryGirl.build(:assignment_without_name).should_not be_valid + end + + it "checks whether Assignment Team is created or not" do + FactoryGirl.create(:assignmentTeam).should be_valid + end + + it "checks whether signed up topic is created or not" do + FactoryGirl.create(:signed_up_topic).should be_valid + end + +end + +describe "#team_assignment" do + it "checks team assignment should be true" do + assign = FactoryGirl.create(:assignment) + res = assign.team_assignment + expect(res).to be true + end +end + +describe "#has_teams?" do + it "checks assignment should have a team" do + assign = FactoryGirl.build(:assignment) + assign_team = FactoryGirl.create(:assignmentTeam) + assign.teams << assign_team + assign.save! + res = assign.has_teams? + expect(res).to be true + end +end + +describe "#has_topics?" do + it "checks assignment should have a topic" do + assign_signed_up_topic = FactoryGirl.create(:signed_up_topic) + assign_topic = FactoryGirl.build(:assignment) + assign_topic.sign_up_topics << assign_signed_up_topic + assign_topic.save! + res = assign_topic.has_topics? + expect(res).to be true + end +end + +describe "#is_wiki_assignment" do + it "checks assignment should be a wiki assignment" do + assign = FactoryGirl.create(:assignment) + id = assign.is_wiki_assignment + expect(id).to be true + end +end + +describe "#is_google_doc" do + it "checks whether assignment is a google doc" do + assign = FactoryGirl.create(:assignment) + res = assign.is_google_doc + expect(res).to be false + end +end + +describe "#is_microtask?" do + it "checks whether assignment is a micro task" do + assign = FactoryGirl.create(:assignment) + id = assign.is_microtask? + expect(id).to be true + end +end + +describe "#dynamic_reviewer_assignment?" do + it "checks the Review Strategy Assignment" do + assign = FactoryGirl.create(:assignment) + id = assign.dynamic_reviewer_assignment? + expect(id).to be true + end +end + +describe "#is_coding_assignment?" do + it "checks assignment should be coding assignment" do + assign = FactoryGirl.create(:assignment).should be_valid + end +end + +describe "#candidate_assignment_teams_to_review" do + it "returns nil if if there are no contributors" do + assign = FactoryGirl.create(:assignment) + reviewer = FactoryGirl.create(:user) + cand_team = assign.candidate_assignment_teams_to_review(reviewer) + expect(cand_team).to be_empty + end + +end + +describe "#candidate_topics_for_quiz" do + it "returns nil if sign up topic is empty" do + assign = FactoryGirl.create(:assignment) + cand_team = assign.candidate_topics_for_quiz + expect(cand_team).to be_nil + end +end diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb new file mode 100644 index 00000000000..16cbdb35e44 --- /dev/null +++ b/spec/models/team_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' +require 'rails_helper' + +describe Team do + it "when team is valid" do + FactoryGirl.build(:team,name: nil).should be_valid + end + + + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3c0eda09b97..b6fcf63bd8d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,5 @@ # Record code coverage with coveralls on Travis +require 'factory_girl_rails' require 'coveralls' Coveralls.wear! 'rails' @@ -27,6 +28,9 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods + +#RSpec.configure do |config| # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. =begin