spec/models/content_spec.rb in alchemy_cms-2.9.1 vs spec/models/content_spec.rb in alchemy_cms-3.0.0.rc5
- old
+ new
@@ -1,7 +1,6 @@
require 'spec_helper'
-require 'ostruct'
module Alchemy
describe Content do
let(:element) { FactoryGirl.create(:element, name: 'headline', :create_contents_after_create => true) }
let(:content) { element.contents.find_by_essence_type('Alchemy::EssenceText') }
@@ -38,28 +37,50 @@
end
end
end
describe '#update_essence' do
- it "should update the attributes of related essence and return true" do
- @element = FactoryGirl.create(:element, :name => 'text', :create_contents_after_create => true)
- @content = @element.contents.first
- @content.update_essence(:body => 'Mikes Petshop')
- @content.ingredient.should == "Mikes Petshop"
+ subject { content.update_essence(params) }
+
+ let(:element) { create(:element, name: 'text', create_contents_after_create: true) }
+ let(:content) { element.contents.first }
+ let(:params) { {} }
+
+ context 'with params given' do
+ let(:params) { {body: 'Mikes Petshop'} }
+ let(:essence) { content.essence }
+
+ before { essence.stub(content: content) }
+
+ it "updates the attributes of related essence and return true" do
+ should be_true
+ content.ingredient.should == "Mikes Petshop"
+ end
+
+ it "updates timestamp after updating related essence" do
+ content.should_receive(:touch)
+ subject
+ end
end
- it "should add error messages if save fails and return false" do
- @element = FactoryGirl.create(:element, :name => 'contactform', :create_contents_after_create => true)
- @content = @element.contents.first
- @content.update_essence
- @content.errors[:essence].should have(1).item
+ context 'with validations and without params given' do
+ let(:element) { create(:element, name: 'contactform', create_contents_after_create: true) }
+
+ it "should add error messages if save fails and return false" do
+ should be_false
+ content.errors[:essence].should have(1).item
+ end
end
- it "should raise error if essence is missing" do
- @element = FactoryGirl.create(:element, :name => 'text', :create_contents_after_create => true)
- @content = @element.contents.first
- @content.update_essence
+ context 'if essence is missing' do
+ before do
+ content.stub(essence: nil)
+ end
+
+ it "should raise error" do
+ expect { subject }.to raise_error
+ end
end
end
describe '.copy' do
before(:each) do
@@ -173,10 +194,12 @@
end
end
end
describe '#ingredient=' do
+ let (:element) { FactoryGirl.create(:element, name: 'headline') }
+
it "should set the given value to the ingredient column of essence" do
c = Content.create_from_scratch(element, name: 'headline')
c.ingredient = "Welcome"
c.ingredient.should == "Welcome"
end
@@ -199,10 +222,43 @@
Content.descriptions.should == []
end
end
end
+ describe "#dom_id" do
+ let(:content) { build_stubbed(:content) }
+
+ it "returns a dom id string" do
+ content.dom_id.should eq("essence_text_#{content.id}")
+ end
+
+ context "without an essence" do
+ before { content.stub(essence: nil) }
+
+ it "returns empty string" do
+ content.dom_id.should eq('')
+ end
+ end
+ end
+
+ describe "#essence_partial_name" do
+ let(:content) { build_stubbed(:content) }
+
+ it "returns the essence#partial_name" do
+ content.essence.should_receive(:partial_name)
+ content.essence_partial_name
+ end
+
+ context "without an essence" do
+ before { content.stub(essence: nil) }
+
+ it "returns empty string" do
+ content.essence_partial_name.should eq('')
+ end
+ end
+ end
+
describe '#preview_text' do
let(:essence) { mock_model(EssenceText, preview_text: 'Lorem') }
let(:content) { c = Content.new; c.essence = essence; c }
it "should return the essences preview_text" do
@@ -220,9 +276,41 @@
context 'having custom tinymce config' do
before { content.stub(:has_custom_tinymce_config?).and_return(true) }
it('returns name including element name') { eq('custom_tinymce article_text') }
end
+ end
+
+ describe '#form_field_name' do
+ let(:content) { Content.new(id: 1) }
+
+ it "returns a name value for form fields with ingredient as default" do
+ content.form_field_name.should == 'contents[1][ingredient]'
+ end
+
+ context 'with a essence column given' do
+ it "returns a name value for form fields for that column" do
+ content.form_field_name(:link_title).should == 'contents[1][link_title]'
+ end
+ end
+ end
+
+ describe '#form_field_id' do
+ let(:content) { Content.new(id: 1) }
+
+ it "returns a id value for form fields with ingredient as default" do
+ content.form_field_id.should == 'contents_1_ingredient'
+ end
+
+ context 'with a essence column given' do
+ it "returns a id value for form fields for that column" do
+ content.form_field_id(:link_title).should == 'contents_1_link_title'
+ end
+ end
+ end
+
+ it_behaves_like "having a hint" do
+ let(:subject) { Content.new }
end
end
end