Sha256: 32f93ab3273d057881368b5c2e732180fa405ba2dfc27047ddde3aba627fcee2

Contents?: true

Size: 1.9 KB

Versions: 8

Compression:

Stored size: 1.9 KB

Contents

require 'rails_helper'
RSpec.describe Admin::ProjectsController, :type => :controller do 
  render_views

  before :each do # Why can't I do this shit in a helper like I do for requests?
    user = double('user')
    allow(request.env['warden']).to receive(:authenticate!) { user }
    allow(controller).to receive(:current_user) { user }
  end

  describe "GET index" do
    it "finds all projects" do
      r = Project.make!
      get :index
      response.status.should == 200 
      assigns(:projects).include?(r).should == true
    end
  end

  describe "SHOW record" do 
    it "finds the record" do
      r = Project.make!
      get :show, id: r.id
      response.status.should == 200 
    end
  end

  describe "NEW record" do 
    it "renders the form for a new record" do
      get :new
      response.status.should == 200 
    end
  end

  describe "CREATE record" do 
    it "creates the record" do
      r = Project.make
      post :create, project: r.attributes
      response.should redirect_to action: :show, id: Project.last.id
      Project.last.name.should == r.name
    end

    it "the inverse_of declaration allows a new project to be created with a project_job" do
      j = Job.make!
      r = Project.make
      post :create, project: r.attributes.merge({project_jobs_attributes:{'0'=>{job_id: j.id}}}) 
      p = Project.last
      p.name.should == r.name
      p.project_jobs.size.should == 1
      p.project_jobs.first.job.should == j
    end

  end

  describe "EDIT record" do 
    it "renders the edit form for an existing record" do 
      r = Project.make!
      get :edit, id: r.id
      response.status.should == 200 
    end
  end

  describe "UPDATE record" do 
    it "updates the record" do
      r = Project.make!
      put :update, id: r.id, project: { name: "New Name" } 
      response.should redirect_to action: :show, id: r.id
      Project.find(r.id).name.should == "New Name"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
introspective_admin-0.0.8 spec/admin/project__admin_spec.rb
introspective_admin-0.0.7 spec/admin/project__admin_spec.rb
introspective_admin-0.0.6 spec/admin/project__admin_spec.rb
introspective_admin-0.0.5 spec/admin/project__admin_spec.rb
introspective_admin-0.0.4 spec/admin/project__admin_spec.rb
introspective_admin-0.0.3 spec/admin/project__admin_spec.rb
introspective_admin-0.0.2 spec/admin/project__admin_spec.rb
introspective_admin-0.0.1 spec/admin/project__admin_spec.rb