Sha256: 131afe9045bff779ba7940f859eb0896e1b7c18400966e17bce90dda1a5ffbc6

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

shared_examples_for "Items Controller CRUD" do
  before do
    @controller_class.should be_present
    @model_class ||= @controller_class.model_class
    @model_name ||= @model_class.alias.underscore
  end
  
  %w{html json}.each do |format|
    it "show :#{format}" do
      @item = Factory.create @model_name    
      call :show, id: @item.to_param, format: format
      response.should be_ok
      response.body.should include(@item.name)
    end
    
    it "all :#{format}" do
      @item = Factory.create @model_name
      call :all, format: format
      response.should be_ok
      response.body.should include(@item.name)
    end
  end
  
  it "edit :js" do
    item = Factory.create @model_name
    call :edit, id: item.to_param, format: 'js'
    response.should be_ok
  end
  
  %w{js json}.each do |format|
    it "new :#{format}" do    
      call :new, format: format
      response.should be_ok
    end
    
    it "create :#{format}" do
      item_attributes = Factory.attributes_for @model_name
      pcall :create, model: item_attributes, format: format

      (format == 'js') ? response.body.should(include('window.location')) : response.should(be_ok)
      @model_class.count.should == 1
      item = @model_class.first
      item.name.should == item_attributes[:name]
    end
    
    it "update :#{format}" do
      item = Factory.create @model_name
      pcall :update, id: item.to_param, model: {name: 'new_name'}, format: format

      response.should be_ok
      response.body.should =~ /new_name|reload/ if format == 'js'

      item.reload
      item.name.should == 'new_name'
    end

    it "destroy :#{format}" do
      item = Factory.create @model_name
      pcall :destroy, id: item.to_param, format: format
      response.should be_ok
      @model_class.count.should == 0
    end
  end            
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rad_kit-0.0.8 lib/kit/spec/items_controller_crud.rb
rad_kit-0.0.7 lib/kit/spec/items_controller_crud.rb
rad_kit-0.0.6 lib/kit/spec/items_controller_crud.rb
rad_kit-0.0.5 lib/kit/spec/items_controller_crud.rb
rad_kit-0.0.4 lib/kit/spec/items_controller_crud.rb
rad_kit-0.0.3 lib/kit/spec/items_controller_crud.rb
rad_kit-0.0.2 lib/kit/spec/items_controller_crud.rb
rad_kit-0.0.1 lib/kit/spec/items_controller_crud.rb