recipient lists

This commit is contained in:
Jared Cosulich 2017-03-02 12:00:40 -05:00
parent ab6cefd055
commit 37e01c024b
24 changed files with 491 additions and 1 deletions

View file

@ -0,0 +1,166 @@
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
RSpec.describe RecipientListsController, type: :controller do
let(:school) { School.create!(name: 'School') }
# This should return the minimal set of attributes required to create a valid
# RecipientList. As you add validations to RecipientList, be sure to
# adjust the attributes here as well.
let(:valid_attributes) {
{
school_id: school.id,
recipient_ids: '1,2,3',
name: 'Parents',
description: 'List of parents.'
}
}
let(:invalid_attributes) {
{school_id: school.id, name: 'Empty List', recipient_ids: ''}
}
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# RecipientListsController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe "GET #index" do
it "assigns all recipient_lists as @recipient_lists" do
recipient_list = RecipientList.create! valid_attributes
get :index, params: {school_id: school.to_param}, session: valid_session
expect(assigns(:recipient_lists)).to eq([recipient_list])
end
end
describe "GET #show" do
it "assigns the requested recipient_list as @recipient_list" do
recipient_list = RecipientList.create! valid_attributes
get :show, params: {school_id: school.to_param, id: recipient_list.to_param}, session: valid_session
expect(assigns(:recipient_list)).to eq(recipient_list)
end
end
describe "GET #new" do
it "assigns a new recipient_list as @recipient_list" do
get :new, params: {school_id: school.to_param}, session: valid_session
expect(assigns(:recipient_list)).to be_a_new(RecipientList)
end
end
describe "GET #edit" do
it "assigns the requested recipient_list as @recipient_list" do
recipient_list = RecipientList.create! valid_attributes
get :edit, params: {school_id: school.to_param, id: recipient_list.to_param}, session: valid_session
expect(assigns(:recipient_list)).to eq(recipient_list)
end
end
describe "POST #create" do
context "with valid params" do
it "creates a new RecipientList" do
expect {
post :create, params: {school_id: school.to_param, recipient_list: valid_attributes}, session: valid_session
}.to change(RecipientList, :count).by(1)
end
it "assigns a newly created recipient_list as @recipient_list" do
post :create, params: {school_id: school.to_param, recipient_list: valid_attributes}, session: valid_session
expect(assigns(:recipient_list)).to be_a(RecipientList)
expect(assigns(:recipient_list)).to be_persisted
end
it "redirects to the created recipient_list" do
post :create, params: {school_id: school.to_param, recipient_list: valid_attributes}, session: valid_session
expect(response).to redirect_to(school_recipient_list_path(school, RecipientList.last))
end
end
context "with invalid params" do
it "assigns a newly created but unsaved recipient_list as @recipient_list" do
post :create, params: {school_id: school.to_param, recipient_list: invalid_attributes}, session: valid_session
expect(assigns(:recipient_list)).to be_a_new(RecipientList)
end
it "re-renders the 'new' template" do
post :create, params: {school_id: school.to_param, recipient_list: invalid_attributes}, session: valid_session
expect(response).to render_template("new")
end
end
end
describe "PUT #update" do
context "with valid params" do
let(:new_attributes) {
{recipient_ids: '3,4,5'}
}
it "updates the requested recipient_list" do
recipient_list = RecipientList.create! valid_attributes
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: new_attributes}, session: valid_session
recipient_list.reload
expect(recipient_list.recipient_ids).to eq('3,4,5')
end
it "assigns the requested recipient_list as @recipient_list" do
recipient_list = RecipientList.create! valid_attributes
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes}, session: valid_session
expect(assigns(:recipient_list)).to eq(recipient_list)
end
it "redirects to the recipient_list" do
recipient_list = RecipientList.create! valid_attributes
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes}, session: valid_session
expect(response).to redirect_to(school_recipient_list_url(school, recipient_list))
end
end
context "with invalid params" do
it "assigns the recipient_list as @recipient_list" do
recipient_list = RecipientList.create! valid_attributes
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes}, session: valid_session
expect(assigns(:recipient_list)).to eq(recipient_list)
end
it "re-renders the 'edit' template" do
recipient_list = RecipientList.create! valid_attributes
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes}, session: valid_session
expect(response).to render_template("edit")
end
end
end
describe "DELETE #destroy" do
it "destroys the requested recipient_list" do
recipient_list = RecipientList.create! valid_attributes
expect {
delete :destroy, params: {school_id: school.to_param, id: recipient_list.to_param}, session: valid_session
}.to change(RecipientList, :count).by(-1)
end
it "redirects to the recipient_lists list" do
recipient_list = RecipientList.create! valid_attributes
delete :destroy, params: {school_id: school.to_param, id: recipient_list.to_param}, session: valid_session
expect(response).to redirect_to(school)
end
end
end

View file

@ -0,0 +1,45 @@
require "rails_helper"
RSpec.describe RecipientListsController, type: :routing do
describe "routing" do
before(:each) do
@school = School.create!(
:name => "MyString",
:district_id => 1
)
end
it "routes to #index" do
expect(:get => "schools/#{@school.id}/recipient_lists").to route_to("recipient_lists#index", school_id: @school.id.to_s)
end
it "routes to #new" do
expect(:get => "schools/#{@school.id}/recipient_lists/new").to route_to("recipient_lists#new", school_id: @school.id.to_s)
end
it "routes to #show" do
expect(:get => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#show", school_id: @school.id.to_s, :id => "1")
end
it "routes to #edit" do
expect(:get => "schools/#{@school.id}/recipient_lists/1/edit").to route_to("recipient_lists#edit", school_id: @school.id.to_s, :id => "1")
end
it "routes to #create" do
expect(:post => "schools/#{@school.id}/recipient_lists").to route_to("recipient_lists#create", school_id: @school.id.to_s)
end
it "routes to #update via PUT" do
expect(:put => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#update", school_id: @school.id.to_s, :id => "1")
end
it "routes to #update via PATCH" do
expect(:patch => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#update", school_id: @school.id.to_s, :id => "1")
end
it "routes to #destroy" do
expect(:delete => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#destroy", school_id: @school.id.to_s, :id => "1")
end
end
end

View file

@ -0,0 +1,29 @@
require 'rails_helper'
RSpec.describe "recipient_lists/edit", type: :view do
before(:each) do
@school = assign(:school, School.create!(
:name => "School"
))
@recipient_list = assign(:recipient_list, RecipientList.create!(
:name => "MyString",
:description => "MyText",
:recipient_ids => "1,2,3",
:school_id => @school.id
))
end
it "renders the edit recipient_list form" do
render
assert_select "form[action=?][method=?]", school_recipient_list_path(@school, @recipient_list), "post" do
assert_select "input#recipient_list_name[name=?]", "recipient_list[name]"
assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]"
assert_select "textarea#recipient_list_recipient_ids[name=?]", "recipient_list[recipient_ids]"
end
end
end

View file

@ -0,0 +1,30 @@
require 'rails_helper'
RSpec.describe "recipient_lists/index", type: :view do
before(:each) do
@school = assign(:school, School.create!(name: 'School'))
assign(:recipient_lists, [
RecipientList.create!(
:name => "Name",
:description => "MyText",
:recipient_ids => "1,2,3",
:school_id => @school.id
),
RecipientList.create!(
:name => "Name",
:description => "MyText",
:recipient_ids => "2,3,4",
:school_id => @school.id
)
])
end
it "renders a list of recipient_lists" 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 => "1,2,3".to_s, :count => 1
assert_select "tr>td", :text => "2,3,4".to_s, :count => 1
end
end

View file

@ -0,0 +1,26 @@
require 'rails_helper'
RSpec.describe "recipient_lists/new", type: :view do
before(:each) do
@school = assign(:school, School.create!(name: 'School'))
@recipient_list = assign(:recipient_list, RecipientList.new(
:name => "MyString",
:description => "MyText",
:recipient_ids => "MyText",
:school_id => @school.id
))
end
it "renders new recipient_list form" do
render
assert_select "form[action=?][method=?]", school_recipient_lists_path(@school, @recipient_list), "post" do
assert_select "input#recipient_list_name[name=?]", "recipient_list[name]"
assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]"
assert_select "textarea#recipient_list_recipient_ids[name=?]", "recipient_list[recipient_ids]"
end
end
end

View file

@ -0,0 +1,20 @@
require 'rails_helper'
RSpec.describe "recipient_lists/show", type: :view do
before(:each) do
@school = assign(:school, School.create!(name: 'School'))
@recipient_list = assign(:recipient_list, RecipientList.create!(
:name => "Name",
:description => "MyText",
:recipient_ids => "MyText",
:school_id => @school.id
))
end
it "renders attributes in <p>" do
render
expect(rendered).to match(/Name/)
expect(rendered).to match(/MyText/)
expect(rendered).to match(/MyText/)
end
end