require 'spec_helper'
describe PowerResource::RenderingHelper do
let(:post) { Post.create(title: 'Test post', content: 'Lorem ipsum dolor') }
before :each do
@controller = PostsController.new
@controller.request = ActionDispatch::TestRequest.new
@controller.instance_variable_set('@post', post)
end
describe '#render_collection_table' do
it 'renders collection table' do
expected = '
'
output = helper.render_collection_table.gsub(/(^ +|\n)/, '')
expect(output).to eq(expected.gsub(/(^ +|\n)/, ''))
end
end
context 'when form builder is form_for' do
context 'with action :edit' do
describe '#render_form' do
it 'renders edit form using form_for' do
expected = '
'
output = helper.render_form.gsub(/(^ +|\n)/, '')
expect(output).to eq(expected.gsub(/(^ +|\n)/, ''))
end
end
end
context 'with action :new' do
before :each do
@controller.request.action = 'new'
@controller.instance_variable_set('@post', Post.new)
end
describe '#render_form' do
it 'renders new form using form_for' do
expected = '
'
output = helper.render_form.gsub(/(^ +|\n)/, '')
expect(output).to eq(expected.gsub(/(^ +|\n)/, ''))
end
end
end
end
### Localization specs
context 'when locale is set' do
before :each do
I18n.locale = :fi
end
after :each do
I18n.locale = I18n.default_locale
end
describe '#render_collection_table' do
it 'renders localized collection table' do
expected = '