rspec views

2999 단어 rspec
본 고 는 firedragonpzy 오리지널 입 니 다. 전 재 는 반드시 뚜렷 한 곳 에 표시 해 야 합 니 다. [Softeware MyZone] 원문 링크 에서 전 재 됩 니 다.http://www.firedragonpzy.com.cn/index.php/archives/475
#coding:utf-8
require 'spec_helper'
require 'will_paginate/array'
describe "admin/roles/index" do
  before(:each) do

    @ability = Object.new
    @ability.extend(CanCan::Ability)
    controller.stub(:current_ability) { @ability }
    view.stub(:current_ability) { @ability }

    assign(:roles, Role.paginate(:page => params[:page],:per_page => 10).order("updated_at DESC"))
  end

  it "has a create link for that role inside admin" do
      @ability.can :create, Role
      render
      if Role.count > 0
          rendered.should have_selector("div") do |new_a|
            new_a.should have_selector "a",
              :href => new_admin_role_path,
              :content => "  "
          end
      end
    end

  it "has a destroy link for that role inside admin" do
    @ability.can :destroy, Role
    render
    if Role.count > 0
        rendered.should have_selector("tr td") do |destroy_a|
          destroy_a.should have_selector "a",
            :href => admin_role_path(Role.first),
            :"data-method" => "delete",
            :"data-confirm" => "    ,                。     ?",
            :rel => "nofollow",
            :content => "  "
        end
    end
  end
  it "has a update link for that role inside admin" do
    @ability.can :update, Role
    render
     if Role.count > 0
        rendered.should have_selector("tr td") do |update_a|
          update_a.should have_selector "a",
            :href => "/admin/roles/"+Role.first.id+"/edit",
            :content => "  "
        end
     end
  end
  it "renders a list of admin/roles" do
    role = Role.first
    @ability.can :destroy, Role
    @ability.can :update, Role
    render
    # Run the generator again with the --webrat flag if you want to use webrat matchers
    allow_message_expectations_on_nil
    assigns[:roles].stub!(:total_pages).and_return(1)
    assert_select "tr>td", :text => role.name.to_s, :count => 1
    assert_select "tr td", :text => role.description.to_s, :count => 1
    mycount = Role.count
    assert_select "a", :html => "  ",:count =>  mycount < 10?mycount:10
    assert_select "a", :html => "  ", :count => mycount < 10?mycount:10
  end
end

좋은 웹페이지 즐겨찾기