dead_simple_cms 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +266 -0
- data/Rakefile +17 -0
- data/dead_simple_cms.gemspec +47 -0
- data/lib/dead_simple_cms.rb +132 -0
- data/lib/dead_simple_cms/attribute/collection.rb +45 -0
- data/lib/dead_simple_cms/attribute/type/all.rb +104 -0
- data/lib/dead_simple_cms/attribute/type/base.rb +79 -0
- data/lib/dead_simple_cms/attribute/type/collection_support.rb +26 -0
- data/lib/dead_simple_cms/configuration.rb +50 -0
- data/lib/dead_simple_cms/file_uploader/base.rb +29 -0
- data/lib/dead_simple_cms/group.rb +58 -0
- data/lib/dead_simple_cms/group/configuration.rb +32 -0
- data/lib/dead_simple_cms/group/presenter.rb +23 -0
- data/lib/dead_simple_cms/rails/action_controller/extensions.rb +24 -0
- data/lib/dead_simple_cms/rails/action_controller/fragment_sweeper.rb +19 -0
- data/lib/dead_simple_cms/rails/action_view/extensions.rb +14 -0
- data/lib/dead_simple_cms/rails/action_view/form_builders/default.rb +16 -0
- data/lib/dead_simple_cms/rails/action_view/form_builders/interface.rb +72 -0
- data/lib/dead_simple_cms/rails/action_view/form_builders/simple_form.rb +43 -0
- data/lib/dead_simple_cms/rails/action_view/form_builders/simple_form_with_bootstrap.rb +19 -0
- data/lib/dead_simple_cms/rails/action_view/presenter.rb +63 -0
- data/lib/dead_simple_cms/section.rb +103 -0
- data/lib/dead_simple_cms/section/builder.rb +73 -0
- data/lib/dead_simple_cms/storage/base.rb +49 -0
- data/lib/dead_simple_cms/storage/database.rb +33 -0
- data/lib/dead_simple_cms/storage/memory.rb +20 -0
- data/lib/dead_simple_cms/storage/rails_cache.rb +19 -0
- data/lib/dead_simple_cms/storage/redis.rb +23 -0
- data/lib/dead_simple_cms/util/identifier.rb +40 -0
- data/lib/dead_simple_cms/util/identifier/dictionary.rb +65 -0
- data/lib/dead_simple_cms/version.rb +3 -0
- data/spec/dead_simple_cms/attribute/collection_spec.rb +46 -0
- data/spec/dead_simple_cms/attribute/type/all_spec.rb +252 -0
- data/spec/dead_simple_cms/attribute/type/base_spec.rb +117 -0
- data/spec/dead_simple_cms/configuration_spec.rb +117 -0
- data/spec/dead_simple_cms/file_uploader/base_spec.rb +35 -0
- data/spec/dead_simple_cms/group/configuration_spec.rb +24 -0
- data/spec/dead_simple_cms/group/presenter_spec.rb +28 -0
- data/spec/dead_simple_cms/group_spec.rb +65 -0
- data/spec/dead_simple_cms/rails/action_view/form_builders/default_spec.rb +8 -0
- data/spec/dead_simple_cms/rails/action_view/form_builders/simple_form_spec.rb +8 -0
- data/spec/dead_simple_cms/rails/action_view/form_builders/simple_form_with_bootstrap_spec.rb +8 -0
- data/spec/dead_simple_cms/rails/action_view/fragment_sweeper_spec.rb +22 -0
- data/spec/dead_simple_cms/rails/action_view/presenter_spec.rb +54 -0
- data/spec/dead_simple_cms/section/builder_spec.rb +28 -0
- data/spec/dead_simple_cms/section_spec.rb +78 -0
- data/spec/dead_simple_cms/storage/base_spec.rb +59 -0
- data/spec/dead_simple_cms/storage/database_spec.rb +51 -0
- data/spec/dead_simple_cms/storage/memory_spec.rb +25 -0
- data/spec/dead_simple_cms/storage/rails_cache_spec.rb +33 -0
- data/spec/dead_simple_cms/storage/redis_spec.rb +33 -0
- data/spec/dead_simple_cms/util/identifier/dictionary/duplciate_item_spec.rb +10 -0
- data/spec/dead_simple_cms/util/identifier/dictionary/invalid_entry_class_spec.rb +10 -0
- data/spec/dead_simple_cms/util/identifier/dictionary_spec.rb +42 -0
- data/spec/dead_simple_cms/util/identifier_spec.rb +27 -0
- data/spec/setup.rb +26 -0
- data/spec/setup/banner_presenter.rb +19 -0
- data/spec/setup/rspec_template_builder.rb +104 -0
- data/spec/setup/shared.rb +57 -0
- data/spec/setup/test_file_uploader.rb +12 -0
- data/spec/spec_helper.rb +48 -0
- metadata +221 -0
@@ -0,0 +1,117 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Attribute::Type::Base do
|
4
|
+
|
5
|
+
module DeadSimpleCMS
|
6
|
+
module Attribute
|
7
|
+
module Type
|
8
|
+
class FakeAttribute < Base
|
9
|
+
self.default_input_type = :string
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:fake_attribute_class) { DeadSimpleCMS::Attribute::Type::FakeAttribute }
|
16
|
+
let(:group_hierarchy) do
|
17
|
+
klass = DeadSimpleCMS::Group
|
18
|
+
[klass.root, klass.new(:second), klass.new(:third)]
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { fake_attribute_class.new(:fake_identifier, :label => "Fake Label", :default => 413, :hint => "some hint",
|
22
|
+
:group_hierarchy => group_hierarchy) }
|
23
|
+
|
24
|
+
describe ".builder_method_name" do
|
25
|
+
it "should derive from the class name" do
|
26
|
+
fake_attribute_class.builder_method_name.should == "fake_attribute"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
its(:label) { should == "Fake Label" }
|
31
|
+
its(:identifier) { should == :fake_identifier }
|
32
|
+
its(:default_input_type) { should == :string }
|
33
|
+
its(:input_type) { should == :string }
|
34
|
+
its(:hint) { should == "some hint" }
|
35
|
+
its(:required) { should be false }
|
36
|
+
its(:group_hierarchy) { should == group_hierarchy }
|
37
|
+
its(:section_identifier) { should == :root_second_third_fake_identifier }
|
38
|
+
|
39
|
+
describe "#label=" do
|
40
|
+
it "should be able to set a new label" do
|
41
|
+
subject.label = "New Label"
|
42
|
+
subject.label.should == "New Label"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#root_group?" do
|
47
|
+
|
48
|
+
its (:root_group?) { should be false }
|
49
|
+
|
50
|
+
context "when last group is root" do
|
51
|
+
before(:each) { subject.group_hierarchy << DeadSimpleCMS::Group.root }
|
52
|
+
|
53
|
+
its (:root_group?) { should be true }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#default" do
|
58
|
+
|
59
|
+
its (:default) { should == 413 }
|
60
|
+
|
61
|
+
context "when default is passed in as a Proc" do
|
62
|
+
before(:each) do
|
63
|
+
delayed_value = 123
|
64
|
+
subject.instance_variable_set(:@default, lambda { delayed_value } )
|
65
|
+
end
|
66
|
+
|
67
|
+
its (:default) { should == 123 }
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#value" do
|
73
|
+
|
74
|
+
context "when @value is set" do
|
75
|
+
before(:each) { subject.instance_variable_set(:@value, nil) }
|
76
|
+
|
77
|
+
its(:value) { should be nil }
|
78
|
+
|
79
|
+
it "should not attempt to hit the storage" do
|
80
|
+
subject.should_receive(:attributes_from_storage).never
|
81
|
+
subject.value
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when @value is not set" do
|
86
|
+
it "should read the attribute from the storage" do
|
87
|
+
subject.should_receive(:attributes_from_storage).and_return(subject.section_identifier => :bar)
|
88
|
+
subject.value.should == :bar
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not fallback on the default if the attribute is present in the storage" do
|
92
|
+
subject.should_receive(:attributes_from_storage).and_return(subject.section_identifier => nil)
|
93
|
+
subject.value.should be nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#value=" do
|
100
|
+
|
101
|
+
it "should convert the value" do
|
102
|
+
subject.should_receive(:convert_value).with("value")
|
103
|
+
subject.value = "value"
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#convert_value" do
|
109
|
+
|
110
|
+
it "should return nil if the value is blank" do
|
111
|
+
subject.send(:convert_value, "").should be nil
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Configuration do
|
4
|
+
|
5
|
+
describe "#section" do
|
6
|
+
|
7
|
+
let(:identifier) { :some_section }
|
8
|
+
|
9
|
+
around(:each) do |example|
|
10
|
+
subject.section(identifier)
|
11
|
+
example.run
|
12
|
+
DeadSimpleCMS.sections.delete(identifier)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should create a helper method for the section" do
|
16
|
+
DeadSimpleCMS.sections.should respond_to(identifier)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should add the section to DeadSimpleCMS.sections" do
|
20
|
+
DeadSimpleCMS.sections.key?(identifier)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#group_configuration" do
|
25
|
+
|
26
|
+
let(:identifier) { :some_group_configuration }
|
27
|
+
|
28
|
+
around(:each) do |example|
|
29
|
+
subject.group_configuration(identifier) { }
|
30
|
+
example.run
|
31
|
+
DeadSimpleCMS.group_configurations.delete(identifier)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "shoudl add the group configuration to the DeadSimpleCMS.group_configurations" do
|
35
|
+
DeadSimpleCMS.group_configurations.key?(identifier)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#register_attribute_classes" do
|
41
|
+
|
42
|
+
let(:attribute_class) { DeadSimpleCMS::Attribute::Type::Text }
|
43
|
+
|
44
|
+
it "should define an attribute method on the Section::Builder class" do
|
45
|
+
DeadSimpleCMS::Section::Builder.should_receive(:define_attribute_builder_method).with(attribute_class)
|
46
|
+
subject.register_attribute_classes(attribute_class)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "shoudl define an attribute method on the Group::Configuration class" do
|
50
|
+
DeadSimpleCMS::Group::Configuration.should_receive(:define_attribute_builder_method).with(attribute_class)
|
51
|
+
subject.register_attribute_classes(attribute_class)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#storage_class" do
|
57
|
+
|
58
|
+
around(:each) do |example|
|
59
|
+
tmp = DeadSimpleCMS::Section.storage_class
|
60
|
+
example.run
|
61
|
+
DeadSimpleCMS::Section.storage_class = tmp
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should set the storage class with a Symbol" do
|
65
|
+
subject.storage_class :database
|
66
|
+
subject.storage_class.should == DeadSimpleCMS::Storage::Database
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#storage_serializer_class" do
|
72
|
+
|
73
|
+
around(:each) do |example|
|
74
|
+
tmp = DeadSimpleCMS::Storage::Base.serializer_class
|
75
|
+
example.run
|
76
|
+
DeadSimpleCMS::Storage::Base.serializer_class = tmp
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should set the storage serializer" do
|
80
|
+
subject.storage_serializer_class(:klass)
|
81
|
+
subject.storage_serializer_class.should == :klass
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#default_form_builder" do
|
87
|
+
|
88
|
+
around(:each) do |example|
|
89
|
+
tmp = DeadSimpleCMS::Rails::ActionView::Presenter.form_builder
|
90
|
+
example.run
|
91
|
+
DeadSimpleCMS::Rails::ActionView::Presenter.form_builder = tmp
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should set the default form builder with a symbol" do
|
95
|
+
subject.default_form_builder(:default)
|
96
|
+
subject.default_form_builder.should == DeadSimpleCMS::Rails::ActionView::FormBuilders::Default
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#file_uploader_class" do
|
102
|
+
|
103
|
+
around(:each) do |example|
|
104
|
+
tmp = DeadSimpleCMS::Attribute::Type::File.uploader_class
|
105
|
+
example.run
|
106
|
+
DeadSimpleCMS::Attribute::Type::File.uploader_class = tmp
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should set the file uploader class" do
|
110
|
+
subject.file_uploader_class(:klass)
|
111
|
+
subject.file_uploader_class.should == :klass
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::FileUploader::Base do
|
4
|
+
|
5
|
+
let(:file_attribute) do
|
6
|
+
DeadSimpleCMS::Attribute::Type::File.new(:image, :file_ext => "jpg").tap do |file_attribute|
|
7
|
+
file_attribute.data = :data
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
subject { described_class.new(file_attribute) }
|
12
|
+
|
13
|
+
its(:file_attribute) { should == file_attribute }
|
14
|
+
its(:file_ext) { should == file_attribute.file_ext }
|
15
|
+
its(:data) { should == file_attribute.data }
|
16
|
+
|
17
|
+
specify { lambda { subject.upload! }.should raise_error(NotImplementedError, "Please overwrite this with your own upload functionality.") }
|
18
|
+
specify { lambda { subject.url }.should raise_error(NotImplementedError, "Please overwrite this with your own url constructor.") }
|
19
|
+
|
20
|
+
describe "#path" do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
file_attribute.stub(:group_hierarchy).and_return([DeadSimpleCMS::Group.new(:foo), DeadSimpleCMS::Group.new(:bar)])
|
24
|
+
file_attribute.stub(:section).and_return(DeadSimpleCMS::Section.new(:car))
|
25
|
+
end
|
26
|
+
|
27
|
+
its(:path) { should == "dead_simple_cms/car/foo/bar/image.jpg" }
|
28
|
+
|
29
|
+
it "should remove nils when joining" do
|
30
|
+
subject.path(nil).should == "car/foo/bar/image.jpg"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Group::Configuration do
|
4
|
+
|
5
|
+
let(:options) { {} }
|
6
|
+
|
7
|
+
subject do
|
8
|
+
described_class.new(:group_configuration_identifier, options) do
|
9
|
+
string :string_var, :default => true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
include_examples :group_display
|
14
|
+
|
15
|
+
its(:identifier) { should == :group_configuration_identifier }
|
16
|
+
|
17
|
+
describe ".define_attribute_builder_method" do
|
18
|
+
|
19
|
+
it "should add to the attribute_arguments" do
|
20
|
+
subject.attribute_arguments[:string_var].should == ["string", {:default => true}]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Group::Presenter do
|
4
|
+
|
5
|
+
let(:view_context) { double("view context") }
|
6
|
+
let(:group) { DeadSimpleCMS::Group.new(:group_identifier) }
|
7
|
+
let(:sample_presenter_class) do
|
8
|
+
Class.new(described_class) do
|
9
|
+
attr_reader :sample_argument
|
10
|
+
def initialize_extra_arguments(sample_argument)
|
11
|
+
@sample_argument = sample_argument
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { sample_presenter_class.new(view_context, group, "sample argument") }
|
17
|
+
|
18
|
+
its(:group) { should == group }
|
19
|
+
|
20
|
+
its(:sample_argument) { should == "sample argument" }
|
21
|
+
|
22
|
+
it "should delegate methods to the view_context" do
|
23
|
+
view_context.stub(:some_method).and_return(:value)
|
24
|
+
subject.some_method.should == :value
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Group do
|
4
|
+
|
5
|
+
let(:options) { {} }
|
6
|
+
subject { described_class.new(:group_identifier, options) }
|
7
|
+
|
8
|
+
its(:identifier) { should == :group_identifier }
|
9
|
+
its(:groups) { should be_an_instance_of DeadSimpleCMS::Util::Identifier::Dictionary }
|
10
|
+
|
11
|
+
include_examples :group_display
|
12
|
+
|
13
|
+
describe ".root" do
|
14
|
+
specify { described_class.root.should be_an_instance_of described_class }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#presenter" do
|
18
|
+
context "when presenter_class is set" do
|
19
|
+
|
20
|
+
let(:presenter_class) { Struct.new(:view_context) }
|
21
|
+
|
22
|
+
before(:each) { subject.display(presenter_class) }
|
23
|
+
|
24
|
+
specify { subject.presenter(:view_context).should be_an_instance_of presenter_class }
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#render" do
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#root?" do
|
34
|
+
|
35
|
+
its(:root?) { should be false }
|
36
|
+
|
37
|
+
context "when identifier is ROOT_IDENTIFIER" do
|
38
|
+
subject { described_class.new(described_class::ROOT_IDENTIFIER) }
|
39
|
+
its(:root?) { should be true }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#add_group" do
|
45
|
+
|
46
|
+
let(:nested_group) { described_class.new(:nested_group) }
|
47
|
+
before(:each) { subject.add_group(nested_group) }
|
48
|
+
|
49
|
+
it "should add the group to the #groups" do
|
50
|
+
subject.groups.keys.should include(:nested_group)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should create a group reader and return it" do
|
54
|
+
subject.nested_group.should == nested_group
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should create an _attributes= writer" do
|
58
|
+
nested_group.should_receive(:update_attributes).with(:value)
|
59
|
+
subject.nested_group_attributes = :value
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Rails::ActionView::FragmentSweeper do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".instance" do
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#observed_classes" do
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#after_save" do
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|