Skip to content

Commit

Permalink
Merge pull request #1 from dburcal/dburcal-testing_issue_971
Browse files Browse the repository at this point in the history
Dburcal testing issue 971
  • Loading branch information
dburcal committed Mar 27, 2018
2 parents 7789d9e + ef8ff0e commit 603b2ba
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 7 deletions.
23 changes: 23 additions & 0 deletions app/assets/javascripts/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@ function toggleSingleTeamAndMember(i) {
}
}

function manageTopics(assignmentId) {
$.getJSON({
url: "/sign_up_sheet/retrieve_topics",
data: {
id: assignmentId
},
success: function(topics) {
$("#manage-topics").jsGrid({
controller: topics,
height: "70%",
width: "100%",
editing: true,
autoload: true,
paging: true
});
},
error: function(err) {
alert(err);
}
});

}

jQuery("input[id^='due_date_']").datetimepicker({
dateFormat: 'yy/mm/dd',
timeFormat: 'HH:mm:ss',
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/sign_up_sheet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ def load_add_signup_topics(assignment_id)
@participants = SignedUpTeam.find_team_participants(assignment_id, session[:ip])
end

def retrieve_topics
if !SignUpTopic.find_by_assignment(params[:id]).nil?
render json: SignUpTopic.find_by_assignment(params[:id])
else
render json: "[]"
end
end

def persist_topics
topics = params[:topics]
end

def set_values_for_new_topic
@sign_up_topic = SignUpTopic.new
@sign_up_topic.topic_identifier = params[:topic][:topic_identifier]
Expand Down
6 changes: 6 additions & 0 deletions app/models/sign_up_topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class SignUpTopic < ActiveRecord::Base
has_many :bids, foreign_key: 'topic_id', dependent: :destroy
belongs_to :assignment

require 'json'

has_paper_trail

# the below relations have been added to make it consistent with the database schema
Expand Down Expand Up @@ -157,4 +159,8 @@ def users_on_waiting_list
end
waitlisted_users.flatten
end

def self.find_by_assignment(assignment_id)
SignUpTopic.where(assignment_id: assignment_id)
end
end
4 changes: 2 additions & 2 deletions app/views/assignments/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<li><a href="#tabs-6" id="Calibration">Calibration</a></li>
<% end %>
<% if @assignment_form.assignment.has_badge? %>
<li><a href="#tabs-7" id="Badges">Badges</li>
<li><a href="#tabs-7" id="Badges">Badges</a></li>
<% end %>
</ul>
<div id="tabs-1">
Expand Down Expand Up @@ -76,7 +76,7 @@
</div>
<script>
var useBookmarkChanged = function () {
jQuery("#questionnaire_table_BookmarkRatingQuestionnaire").remove()
jQuery("#questionnaire_table_BookmarkRatingQuestionnaire").remove();
var bookmark_checkbox = jQuery('#assignment_form_assignment_use_bookmark');
if (bookmark_checkbox.is(':checked')) {
addQuestionnaireTableRow(
Expand Down
6 changes: 5 additions & 1 deletion app/views/sign_up_sheet/_add_topics.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= link_to 'Manage topics', "javascript:manageTopics(#{params[:id]})", :remote => true, "data-target": "manage-topics", "data-toggle": "modal"%>
<% if @sign_up_topics.count == 0%>
<%= link_to 'New topic',
Expand Down Expand Up @@ -56,4 +58,6 @@
'&nbsp&nbsp|&nbsp&nbsp' +
'Topic Link <em>(optional)</em>' %> |

<% end %>
<% end %>

<div class="modal hide fade" id="manage-topics"></div>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
get :delete_signup
get :add_signup_topics
get :add_signup_topics_staggered
get :retrieve_topics
get :delete_signup
get :list
get :signup_topics
Expand All @@ -329,6 +330,7 @@
post :signup_as_instructor_action
post :set_priority
post :save_topic_deadlines
post :persist_topics
end
end

Expand Down
71 changes: 71 additions & 0 deletions spec/controllers/assignments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@
let(:instructor2) { build(:instructor, id: 66) }
let(:ta) { build(:teaching_assistant, id: 8) }
let(:student) { build(:student) }
let(:due_date) { build(:assignment_due_date, deadline_type_id: 1) }
let(:due_date2) { build(:assignment_due_date, deadline_type_id: 2) }
let(:team) { build(:team, id: 1, parent_id: 1) }
let(:teams_user) { build(:teams_user, id: 1, team_id: 1) }
let(:assignment_participant) { build(:assignment_particpant, id: 1) }
let(:topic) { build(:topic, id: 1) }
#let(:team) { Team.new(id: 1, advertise_for_partner: 1) }
#let(:signed_up_team) { build(:signed_up_team, id: 1, topic_id: 1) }
before(:each) do
allow(Assignment).to receive(:find).with('1').and_return(assignment)
#allow(Team).to receive(:find).with('1').and_return(advertise_for_partners)
stub_current_user(instructor, instructor.role.name, instructor.role)
end

Expand Down Expand Up @@ -172,6 +181,68 @@
expect(response).to render_template(:edit)
end
end

context 'assignment due dates have not passed' do
before(:each) do
due_date.due_at = DateTime.now.in_time_zone + 1.day
allow(assignment.due_dates).to receive(:find_by).with(deadline_type_id: 6).and_return(due_date)
end
it 'allows a topic to be edited' do
params = {id: 1, anchor: 'tabs-2'}
get :edit, params, xhr: true
expect(response).to respond_to(:edit)
end

it 'allows a topic to be deleted' do
params = {id: 1, anchor: 'tabs-2'}
get :edit, params, xhr: false
expect(response).to respond_to(:destroy)
end

it 'allows a new topic to be added' do
params = {id: 1, anchor: 'tabs-2'}
get :edit, params, xhr: true
expect(response).to respond_to(:new)
end
end

context 'all assignment due dates have passed' do
before(:each) do
due_date.due_at = DateTime.now.in_time_zone - 1.day
allow(assignment.due_dates).to receive(:find_by).with(deadline_type_id: 6).and_return(due_date)
end
it 'does not allow a topic to be edited' do
params = {id: 1, anchor: 'tabs-2'}
get :edit, params, xhr: true
expect(response).not_to respond_to(:edit)
end

it 'does not allow a topic to be deleted' do
params = {id: 1, anchor: 'tabs-2'}
get :edit, params, xhr: true
expect(response).not_to respond_to(:destroy)
end

it 'does not allow a new topic to be added' do
params = {id: 1, anchor: 'tabs-2'}
get :edit, params, xhr: true
expect(response).not_to respond_to(:new)
end
end

context 'team has ad', js: true do
it 'displays the ad horn in the manage topics table' do
login_as('instructor6')
visit "/assignments/1/edit#tabs-2"
@team = Team.new(id: 1, advertise_for_partner: 1)
@signed_up_team = SignedUpTeam.new(id: 1, topic_id: 1)
allow(SignUpTopic).to receive(:find).with('1').and_return(topic)
# params = {id: 1}
# get :edit, params, xhr: true, with: '/#tabs-2'
# expect(response).to have_css('img', text: 'ad_horn.png')
expect(response).to have_content("ad_horn.png")
end
end
end

describe '#update' do
Expand Down
16 changes: 12 additions & 4 deletions spec/controllers/sign_up_sheet_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
expect(controller.instance_variable_get(:@sign_up_topic).assignment).to eq(assignment)
expect(response).to render_template(:new)
end

it 'has default available slots of 1' do
params = {id: 1}
get :new, params
expect(response).to have_field('max_choosers', with: '1')
end
end

describe '#create' do
Expand Down Expand Up @@ -124,10 +130,12 @@
end

describe '#edit' do
it 'renders sign_up_sheet#edit page' do
params = {id: 1}
get :edit, params
expect(response).to render_template(:edit)
context 'assignment can be edited' do
it 'renders sign_up_sheet#edit page' do
params = {id: 1}
get :edit, params
expect(response).to render_template(:edit)
end
end
end

Expand Down

0 comments on commit 603b2ba

Please sign in to comment.