我怎么能干这个规格?

时间:2015-03-24 11:29:24

标签: ruby-on-rails ruby rspec

如何干这个规格?一些自定义匹配器,共享示例?我从来没有使用过它们,我会为其他行动提供更多这样的代码。

describe 'Events Permissions' do
  let(:admin) { create(:user_admin) }
  let(:mod) { create(:user_mod) }
  let(:user) { create(:user) }

  let(:link) { create(:link) }
  let(:event) { create(:event) }

  describe 'GET #new' do
    it 'allows admin user to perform action' do
      sign_in admin

      get :new, link: link.id
      expect(flash[:alert]).to_not match(/^You are not authorized to perform this action./)
    end

    it 'allows mod user to perform action' do
      sign_in mod

      get :new, link: link.id
      expect(flash[:alert]).to_not match(/^You are not authorized to perform this action./)
    end

    it 'does not allow user to perform action' do
      sign_in user

      get :new, link: link.id
      expect(flash[:alert]).to match(/^You are not authorized to perform this action./)
    end

    it 'does not allow guest to perform action' do
      get :new, link: link.id
      expect(flash[:alert]).to match(/^You are not authorized to perform this action./)
    end
  end
end

0 个答案:

没有答案