Sha256: 039c86ddd2311cf4d9ebcfea42198af97a917198fa2b756010f8a11cd2285b90

Contents?: true

Size: 1.38 KB

Versions: 27

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

RSpec.describe TypeStation::Admin::PagesController do
  routes { TypeStation::Engine.routes }
  
  before do
    @page = TypeStation::Page.create(title: 'Index page', template_name: 'blank_index')
    @content_text = @page.contents.build(name: :existing_text_field, type: :text)
    @content_text.set('Old value')
  end

  it 'will create any missing fields' do
    patch :update, id: @page.to_param, contents: { field: 'text_field',value: 'My Text', type: 'text'}
    @page.reload
    expect(@page.get(:text_field)).to eq('My Text')
    expect(response.status).to eq(200)
  end

  it 'will create multiple missing fields' do
    patch :update, id: @page.to_param, contents: [{ field: 'text_field',value: 'My Text', type: 'text'}, { field: 'html_field',value: 'html', type: 'html'}]
    expect(response.status).to eq(200)
  end

  it 'will update any existiong fields' do
    expect(@page.contents.first.get).to eq('Old value')
    patch :update, id: @page.to_param, contents: { field: 'existing_text_field',value: 'New value', type: 'text'}
    @page.reload
    expect(@page.get(:existing_text_field)).to eq('New value')
  end

  it 'will allow you to save values that are other than strings' do
    patch :update, id: @page.to_param, contents: { field: 'image_field',value: {url: 'test'}, type: 'image'}
    @page.reload
    expect(@page.get(:image_field)).to eq({'url' => 'test'})
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
type_station-0.7.0 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.6.0 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.5.4 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.5.3 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.5.2 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.5.1 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.4.7 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.4.6 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.4.5 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.4.4 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.4.3 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.4.2 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.4.1 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.4.0 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.3.4 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.3.3 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.3.2 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.3.1 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.3.0 spec/controllers/type_station/admin/pages_controller_spec.rb
type_station-0.2.3 spec/controllers/type_station/admin/pages_controller_spec.rb