Test moderation of fields of an associated model
parent
1752c5a843
commit
d47bc11145
|
@ -1,3 +1,4 @@
|
|||
class Category < ActiveRecord::Base
|
||||
has_one :page
|
||||
accepts_nested_attributes_for :page
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Page < ActiveRecord::Base
|
||||
has_many :links
|
||||
accepts_nested_attributes_for :links
|
||||
|
||||
belongs_to :category
|
||||
end
|
||||
|
|
|
@ -1,24 +1,40 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe TheModerator::Model do
|
||||
subject { Page.new(name: 'Name', content: 'Content') }
|
||||
|
||||
describe '#moderate' do
|
||||
it 'moderates simple field' do
|
||||
subject.moderate(:name)
|
||||
page = Page.new(name: 'Name', content: 'Content')
|
||||
page.moderate(:name)
|
||||
|
||||
expect(subject.moderations).to have(1).moderation
|
||||
expect(subject.name).to be_nil
|
||||
expect(subject.content).to eq('Content')
|
||||
expect(page.moderations).to have(1).moderation
|
||||
expect(page.moderations.first.data[:attributes]).to include(name: 'Name')
|
||||
expect(page.name).to be_nil
|
||||
expect(page.content).to eq('Content')
|
||||
end
|
||||
|
||||
it 'moderates association fields' do
|
||||
category = Category.new(name: 'category')
|
||||
category.create_page
|
||||
category.save
|
||||
|
||||
category.attributes = {page_attributes: {
|
||||
name: 'name', content: 'content', id: category.page.id}}
|
||||
category.moderate(page: :name)
|
||||
|
||||
expect(category.moderations).to have(1).moderation
|
||||
expect(category.moderations.first.data[:attributes])
|
||||
.to include(page_attributes: {name: 'name', id: category.page.id})
|
||||
expect(category.page.name).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#moderated?' do
|
||||
it 'detects moderated field' do
|
||||
subject.moderate(:name)
|
||||
page = Page.new(name: 'Name', content: 'Content')
|
||||
page.moderate(:name)
|
||||
|
||||
expect(subject.moderated?(:name)).to be_true
|
||||
expect(subject.moderated?(:content)).to be_false
|
||||
expect(page.moderated?(:name)).to be_true
|
||||
expect(page.moderated?(:content)).to be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue