adding more authentication, fixing category bug

This commit is contained in:
Jared Cosulich 2017-04-13 11:29:56 -04:00
parent 60a2982724
commit 42fd3edbae
10 changed files with 28 additions and 93 deletions

View file

@ -23,6 +23,7 @@ RSpec.describe QuestionsController, type: :controller do
# This should return the minimal set of attributes required to create a valid
# Question. As you add validations to Question, be sure to
# adjust the attributes here as well.
let!(:user) { User.create(email: 'test@test.com', password: '123456') }
let (:category) { Category.create!(name: 'Category') }
let(:valid_attributes) {
{
@ -45,6 +46,10 @@ RSpec.describe QuestionsController, type: :controller do
# QuestionsController. Be sure to keep this updated too.
let(:valid_session) { {} }
before :each do
sign_in user
end
describe "GET #index" do
it "assigns all questions as @questions" do
question = Question.create! valid_attributes

View file

@ -20,6 +20,7 @@ require 'rails_helper'
RSpec.describe SchedulesController, type: :controller do
let!(:user) { User.create(email: 'test@test.com', password: '123456') }
let!(:school) { School.create!(name: 'School') }
let!(:recipients) { create_recipients(school, 3) }
@ -54,12 +55,9 @@ RSpec.describe SchedulesController, type: :controller do
# SchedulesController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe "GET #index" do
it "assigns all schedules as @schedules" do
schedule = Schedule.create! valid_attributes
get :index, params: {school_id: school.id}, session: valid_session
expect(assigns(:schedules)).to eq([schedule])
end
before :each do
user.user_schools.create(school: school)
sign_in user
end
describe "GET #show" do

View file

@ -93,7 +93,7 @@ RSpec.describe Attempt, type: :model do
it 'should contact the Twilio API' do
expect(FakeSMS.messages.length).to eq(1)
expect(FakeSMS.messages.last.body).to eq("Question 0:1\nOption 0:1 A: Reply 1\n\rOption 0:1 B: Reply 2\n\rOption 0:1 C: Reply 3\n\rOption 0:1 D: Reply 4\n\rOption 0:1 E: Reply 5\n\rReply 'stop' to stop these messages.")
expect(FakeSMS.messages.last.body).to eq("Question 0:1\n\rOption 0:1 A: Reply 1\n\rOption 0:1 B: Reply 2\n\rOption 0:1 C: Reply 3\n\rOption 0:1 D: Reply 4\n\rOption 0:1 E: Reply 5\n\rReply 'stop' to stop these messages.")
expect(FakeSMS.messages.last.to).to eq('1111111111')
end

View file

@ -1,46 +0,0 @@
require 'rails_helper'
RSpec.describe "schedules/index", type: :view do
before(:each) do
@question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3])
@school = assign(:school, School.create!(name: 'School'))
@recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school)
assign(:schedules, [
Schedule.create!(
:name => "Name",
:description => "MyText",
:school_id => @school.id,
:frequency_hours => 3,
:active => false,
:random => false,
:recipient_list_id => @recipient_list.id,
:question_list_id => @question_list.id
),
Schedule.create!(
:name => "Name",
:description => "MyText",
:school_id => @school.id,
:frequency_hours => 3,
:active => false,
:random => true,
:recipient_list_id => @recipient_list.id,
:question_list_id => @question_list.id,
)
])
end
it "renders a list of schedules" do
render
assert_select "tr>td", :text => "Name".to_s, :count => 2
assert_select "tr>td", :text => "MyText".to_s, :count => 2
assert_select "tr>td", :text => @school.name, :count => 2
assert_select "tr>td", :text => 3.to_s, :count => 2
assert_select "tr>td", :text => false.to_s, :count => 3
assert_select "tr>td", :text => true.to_s, :count => 1
assert_select "tr>td", :text => @recipient_list.name, :count => 2
assert_select "tr>td", :text => @question_list.name, :count => 2
end
end