forked from bofh/fetsite
Introducing Lecturers
This commit is contained in:
160
spec/controllers/lecturers_controller_spec.rb
Normal file
160
spec/controllers/lecturers_controller_spec.rb
Normal file
@@ -0,0 +1,160 @@
|
||||
require 'spec_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.
|
||||
|
||||
describe LecturersController do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Lecturer. As you add validations to Lecturer, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) { { "name" => "MyString" } }
|
||||
|
||||
# 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
|
||||
# LecturersController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET index" do
|
||||
it "assigns all lecturers as @lecturers" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
get :index, {}, valid_session
|
||||
assigns(:lecturers).should eq([lecturer])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET show" do
|
||||
it "assigns the requested lecturer as @lecturer" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
get :show, {:id => lecturer.to_param}, valid_session
|
||||
assigns(:lecturer).should eq(lecturer)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
it "assigns a new lecturer as @lecturer" do
|
||||
get :new, {}, valid_session
|
||||
assigns(:lecturer).should be_a_new(Lecturer)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET edit" do
|
||||
it "assigns the requested lecturer as @lecturer" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
get :edit, {:id => lecturer.to_param}, valid_session
|
||||
assigns(:lecturer).should eq(lecturer)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST create" do
|
||||
describe "with valid params" do
|
||||
it "creates a new Lecturer" do
|
||||
expect {
|
||||
post :create, {:lecturer => valid_attributes}, valid_session
|
||||
}.to change(Lecturer, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created lecturer as @lecturer" do
|
||||
post :create, {:lecturer => valid_attributes}, valid_session
|
||||
assigns(:lecturer).should be_a(Lecturer)
|
||||
assigns(:lecturer).should be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created lecturer" do
|
||||
post :create, {:lecturer => valid_attributes}, valid_session
|
||||
response.should redirect_to(Lecturer.last)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "assigns a newly created but unsaved lecturer as @lecturer" do
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Lecturer.any_instance.stub(:save).and_return(false)
|
||||
post :create, {:lecturer => { "name" => "invalid value" }}, valid_session
|
||||
assigns(:lecturer).should be_a_new(Lecturer)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Lecturer.any_instance.stub(:save).and_return(false)
|
||||
post :create, {:lecturer => { "name" => "invalid value" }}, valid_session
|
||||
response.should render_template("new")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT update" do
|
||||
describe "with valid params" do
|
||||
it "updates the requested lecturer" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
# Assuming there are no other lecturers in the database, this
|
||||
# specifies that the Lecturer created on the previous line
|
||||
# receives the :update_attributes message with whatever params are
|
||||
# submitted in the request.
|
||||
Lecturer.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" })
|
||||
put :update, {:id => lecturer.to_param, :lecturer => { "name" => "MyString" }}, valid_session
|
||||
end
|
||||
|
||||
it "assigns the requested lecturer as @lecturer" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
put :update, {:id => lecturer.to_param, :lecturer => valid_attributes}, valid_session
|
||||
assigns(:lecturer).should eq(lecturer)
|
||||
end
|
||||
|
||||
it "redirects to the lecturer" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
put :update, {:id => lecturer.to_param, :lecturer => valid_attributes}, valid_session
|
||||
response.should redirect_to(lecturer)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with invalid params" do
|
||||
it "assigns the lecturer as @lecturer" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Lecturer.any_instance.stub(:save).and_return(false)
|
||||
put :update, {:id => lecturer.to_param, :lecturer => { "name" => "invalid value" }}, valid_session
|
||||
assigns(:lecturer).should eq(lecturer)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
# Trigger the behavior that occurs when invalid params are submitted
|
||||
Lecturer.any_instance.stub(:save).and_return(false)
|
||||
put :update, {:id => lecturer.to_param, :lecturer => { "name" => "invalid value" }}, valid_session
|
||||
response.should render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "destroys the requested lecturer" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, {:id => lecturer.to_param}, valid_session
|
||||
}.to change(Lecturer, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the lecturers list" do
|
||||
lecturer = Lecturer.create! valid_attributes
|
||||
delete :destroy, {:id => lecturer.to_param}, valid_session
|
||||
response.should redirect_to(lecturers_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
10
spec/factories/lecturers.rb
Normal file
10
spec/factories/lecturers.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :lecturer do
|
||||
name "MyString"
|
||||
email "MyString"
|
||||
oid 1
|
||||
picture "MyString"
|
||||
end
|
||||
end
|
||||
15
spec/helpers/lecturers_helper_spec.rb
Normal file
15
spec/helpers/lecturers_helper_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the LecturersHelper. For example:
|
||||
#
|
||||
# describe LecturersHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
describe LecturersHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
5
spec/models/lecturer_spec.rb
Normal file
5
spec/models/lecturer_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Lecturer do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
11
spec/requests/lecturers_spec.rb
Normal file
11
spec/requests/lecturers_spec.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Lecturers" do
|
||||
describe "GET /lecturers" do
|
||||
it "works! (now write some real specs)" do
|
||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
|
||||
get lecturers_path
|
||||
response.status.should be(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
35
spec/routing/lecturers_routing_spec.rb
Normal file
35
spec/routing/lecturers_routing_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe LecturersController do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
get("/lecturers").should route_to("lecturers#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
get("/lecturers/new").should route_to("lecturers#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
get("/lecturers/1").should route_to("lecturers#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
get("/lecturers/1/edit").should route_to("lecturers#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
post("/lecturers").should route_to("lecturers#create")
|
||||
end
|
||||
|
||||
it "routes to #update" do
|
||||
put("/lecturers/1").should route_to("lecturers#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
delete("/lecturers/1").should route_to("lecturers#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
24
spec/views/lecturers/edit.html.erb_spec.rb
Normal file
24
spec/views/lecturers/edit.html.erb_spec.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "lecturers/edit" do
|
||||
before(:each) do
|
||||
@lecturer = assign(:lecturer, stub_model(Lecturer,
|
||||
:name => "MyString",
|
||||
:email => "MyString",
|
||||
:oid => 1,
|
||||
:picture => "MyString"
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit lecturer form" do
|
||||
render
|
||||
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "form[action=?][method=?]", lecturer_path(@lecturer), "post" do
|
||||
assert_select "input#lecturer_name[name=?]", "lecturer[name]"
|
||||
assert_select "input#lecturer_email[name=?]", "lecturer[email]"
|
||||
assert_select "input#lecturer_oid[name=?]", "lecturer[oid]"
|
||||
assert_select "input#lecturer_picture[name=?]", "lecturer[picture]"
|
||||
end
|
||||
end
|
||||
end
|
||||
29
spec/views/lecturers/index.html.erb_spec.rb
Normal file
29
spec/views/lecturers/index.html.erb_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "lecturers/index" do
|
||||
before(:each) do
|
||||
assign(:lecturers, [
|
||||
stub_model(Lecturer,
|
||||
:name => "Name",
|
||||
:email => "Email",
|
||||
:oid => 1,
|
||||
:picture => "Picture"
|
||||
),
|
||||
stub_model(Lecturer,
|
||||
:name => "Name",
|
||||
:email => "Email",
|
||||
:oid => 1,
|
||||
:picture => "Picture"
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of lecturers" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Email".to_s, :count => 2
|
||||
assert_select "tr>td", :text => 1.to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Picture".to_s, :count => 2
|
||||
end
|
||||
end
|
||||
24
spec/views/lecturers/new.html.erb_spec.rb
Normal file
24
spec/views/lecturers/new.html.erb_spec.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "lecturers/new" do
|
||||
before(:each) do
|
||||
assign(:lecturer, stub_model(Lecturer,
|
||||
:name => "MyString",
|
||||
:email => "MyString",
|
||||
:oid => 1,
|
||||
:picture => "MyString"
|
||||
).as_new_record)
|
||||
end
|
||||
|
||||
it "renders new lecturer form" do
|
||||
render
|
||||
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "form[action=?][method=?]", lecturers_path, "post" do
|
||||
assert_select "input#lecturer_name[name=?]", "lecturer[name]"
|
||||
assert_select "input#lecturer_email[name=?]", "lecturer[email]"
|
||||
assert_select "input#lecturer_oid[name=?]", "lecturer[oid]"
|
||||
assert_select "input#lecturer_picture[name=?]", "lecturer[picture]"
|
||||
end
|
||||
end
|
||||
end
|
||||
21
spec/views/lecturers/show.html.erb_spec.rb
Normal file
21
spec/views/lecturers/show.html.erb_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "lecturers/show" do
|
||||
before(:each) do
|
||||
@lecturer = assign(:lecturer, stub_model(Lecturer,
|
||||
:name => "Name",
|
||||
:email => "Email",
|
||||
:oid => 1,
|
||||
:picture => "Picture"
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
rendered.should match(/Name/)
|
||||
rendered.should match(/Email/)
|
||||
rendered.should match(/1/)
|
||||
rendered.should match(/Picture/)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user