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,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Rails::ActionView::Presenter do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".form_builder?" do
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".form_builder=" do
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".form_builder" do
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#form_builder" do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#form_builder?" do
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#form_builder=" do
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#group" do
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#sections" do
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#with_bootstrap_tabs" do
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#section" do
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#form" do
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Section::Builder do
|
4
|
+
|
5
|
+
include_context :sample_section
|
6
|
+
|
7
|
+
describe "#group" do
|
8
|
+
|
9
|
+
it "should allow for group nesting" do
|
10
|
+
section.groups[:banners].groups[:small].should be_an_instance_of DeadSimpleCMS::Group
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when a group_configuration is specified" do
|
14
|
+
it "should inherit options from a group configuration" do
|
15
|
+
section.banners.small.attributes[:url].required.should be true
|
16
|
+
section.banners.small.attributes[:alt].default.should == "Design Beautiful Books"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#display" do
|
22
|
+
it "should set the presenter class on the group" do
|
23
|
+
section.banners.small.presenter_class.should == DeadSimpleCMS::BannerPresenter
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Section do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
described_class.new(:section_identifier, :path => "/path" )
|
7
|
+
end
|
8
|
+
|
9
|
+
its(:cache_key) { should == "cms/section_identifier" }
|
10
|
+
its(:to_param) { should == "section_identifier" }
|
11
|
+
its(:path) { should == "/path" }
|
12
|
+
|
13
|
+
describe "#root_group" do
|
14
|
+
it "should add the root group on initialize" do
|
15
|
+
section = described_class.new(:section_identifier)
|
16
|
+
section.root_group.should be_an_instance_of DeadSimpleCMS::Group
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#add_attribute" do
|
21
|
+
let(:attribute) { DeadSimpleCMS::Attribute::Type::String.new(:attribute_identifier) }
|
22
|
+
before(:each) { subject.add_attribute(attribute) }
|
23
|
+
|
24
|
+
it "should set the section on the attribute" do
|
25
|
+
attribute.section.should == subject
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when attribute is top level" do
|
29
|
+
before(:each) { attribute.stub(:root?).and_return(true) }
|
30
|
+
|
31
|
+
it "should have alias with just the attribute identfier" do
|
32
|
+
subject.should respond_to :attribute_identifier
|
33
|
+
subject.should respond_to :"attribute_identifier="
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#fragments" do
|
39
|
+
context "when some fragments are proc" do
|
40
|
+
before(:each) do
|
41
|
+
subject.instance_variable_set(:@fragments, [lambda { |x| "hi there" }, 1234])
|
42
|
+
end
|
43
|
+
|
44
|
+
its(:fragments) { should == ["hi there", 1234] }
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#storage" do
|
50
|
+
specify { subject.storage.should be_a DeadSimpleCMS::Storage::Base }
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#update_attributes" do
|
54
|
+
before(:each) do
|
55
|
+
subject.build do
|
56
|
+
string :string_attribute
|
57
|
+
group(:level1) do
|
58
|
+
string :another_string
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
specify do
|
64
|
+
subject.should_receive(:save!)
|
65
|
+
subject.update_attributes(:string_attribute => "value", :level1_another_string => "value1")
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#save!" do
|
71
|
+
it "should call upload_file_attributes before save" do
|
72
|
+
subject.should_receive(:upload_file_attributes).once
|
73
|
+
subject.save!
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Storage::Base do
|
4
|
+
|
5
|
+
include_context :sample_storage
|
6
|
+
|
7
|
+
its(:section) { should == section }
|
8
|
+
|
9
|
+
describe "#read" do
|
10
|
+
|
11
|
+
specify { lambda {subject.read.should receive_error(NotImplementedError) } }
|
12
|
+
|
13
|
+
context "when read_value is defined" do
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
subject.stub(:read_value).and_return(attributes_hash_dump)
|
17
|
+
end
|
18
|
+
|
19
|
+
its(:read) { should == attributes_hash }
|
20
|
+
|
21
|
+
context "and read_value is nil" do
|
22
|
+
before(:each) do
|
23
|
+
subject.stub(:read_value).and_return(nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
its(:read) { should == {} }
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when @_cache is set" do
|
32
|
+
before(:each) { subject.instance_variable_set(:@_cache, attributes_hash) }
|
33
|
+
|
34
|
+
it "should not call #read_value" do
|
35
|
+
subject.should_receive(:read_value).never
|
36
|
+
subject.read
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#write" do
|
42
|
+
|
43
|
+
it "should write_value with dump of attributes_hash" do
|
44
|
+
subject.should_receive(:write_value).with(attributes_hash_dump)
|
45
|
+
subject.write
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should set the @_cache instance variable" do
|
49
|
+
subject.stub(:write_value)
|
50
|
+
subject.write
|
51
|
+
subject.instance_variable_get(:@_cache).should == attributes_hash
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
its(:unique_key) { should == :site_announcement }
|
57
|
+
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Storage::Database do
|
4
|
+
|
5
|
+
include_context :sample_storage
|
6
|
+
|
7
|
+
shared_context :saved_entry do
|
8
|
+
around(:each) do |example|
|
9
|
+
@record = described_class.active_record.create!(key: subject.unique_key, value: "value")
|
10
|
+
example.run
|
11
|
+
@record.destroy
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
specify do
|
17
|
+
described_class.active_record.should == described_class::Table
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#read_value" do
|
21
|
+
|
22
|
+
include_context :saved_entry
|
23
|
+
|
24
|
+
it "should read the record from the database" do
|
25
|
+
subject.send(:read_value).should == "value"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#write_value" do
|
31
|
+
context "when record already exists" do
|
32
|
+
|
33
|
+
include_context :saved_entry
|
34
|
+
|
35
|
+
it "should update the value on the record" do
|
36
|
+
subject.send(:write_value, "value1")
|
37
|
+
@record.reload.value.should == "value1"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when record does not exist" do
|
43
|
+
|
44
|
+
it "should add the entry to the database" do
|
45
|
+
lambda { subject.send(:write_value, "value1") }.should change(described_class::Table, :count).by(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Storage::Memory do
|
4
|
+
|
5
|
+
include_context :sample_storage
|
6
|
+
|
7
|
+
let(:attributes_hash) { {:foo => 1, :bar => 2} }
|
8
|
+
subject { described_class.new(section) }
|
9
|
+
|
10
|
+
after(:each) do
|
11
|
+
described_class.class_variable_set(:@@cache, {})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return value from @@cache" do
|
15
|
+
subject.send(:read_value)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should write value to @@cache" do
|
19
|
+
subject.send(:write_value, "value")
|
20
|
+
described_class.class_variable_get(:@@cache).should == {:site_announcement => "value"}
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Storage::RailsCache do
|
4
|
+
|
5
|
+
include_context :sample_storage
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
::Rails.stub(:cache).and_return(double("rails cache"))
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#read_value" do
|
12
|
+
it "should read from the rails cache" do
|
13
|
+
::Rails.cache.should_receive(:read).with(subject.unique_key)
|
14
|
+
subject.send(:read_value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#write_value" do
|
19
|
+
it "should write to the rails cache" do
|
20
|
+
::Rails.cache.should_receive(:write).with(subject.unique_key, "value", kind_of(Hash))
|
21
|
+
subject.send(:write_value, "value")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set the expires_in to some time in the future" do
|
25
|
+
::Rails.cache.should_receive(:write).with do |key, value, options|
|
26
|
+
options[:expires_in] > Time.now
|
27
|
+
end
|
28
|
+
subject.send(:write_value, "value")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Storage::Redis do
|
4
|
+
|
5
|
+
include_context :sample_storage
|
6
|
+
|
7
|
+
specify { lambda { described_class.connection }.should raise_error NotImplementedError }
|
8
|
+
specify { lambda { subject.send(:read_value) }.should raise_error NotImplementedError }
|
9
|
+
specify { lambda { subject.send(:write_value, "value") }.should raise_error NotImplementedError }
|
10
|
+
|
11
|
+
context "when Redis is defined" do
|
12
|
+
before(:each) do
|
13
|
+
described_class.stub(:connection).and_return(double("redis connection"))
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#read_value" do
|
17
|
+
it "should read from redis" do
|
18
|
+
described_class.connection.stub(:get).with(subject.unique_key).and_return(:result)
|
19
|
+
subject.send(:read_value).should == :result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#write_value" do
|
24
|
+
it "should write to redis" do
|
25
|
+
described_class.connection.stub(:set).with(subject.unique_key, "value")
|
26
|
+
subject.send(:write_value, "value")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Util::Identifier::Dictionary do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#target_class" do
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#identifier_method" do
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#identifiers" do
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#add" do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#include?" do
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#to_hash" do
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#[]=" do
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#[]" do
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DeadSimpleCMS::Util::Identifier do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
IdentifierTest = Class.new do
|
7
|
+
include DeadSimpleCMS::Util::Identifier
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:sample_class) { IdentifierTest }
|
12
|
+
|
13
|
+
subject do
|
14
|
+
sample_class.new("identify_me", :label => "Call me Al!")
|
15
|
+
end
|
16
|
+
|
17
|
+
its(:label) { should == "Call me Al!"}
|
18
|
+
its(:identifier) { should == :identify_me }
|
19
|
+
|
20
|
+
describe("ClassMethods") do
|
21
|
+
subject { sample_class }
|
22
|
+
|
23
|
+
its(:new_dictionary) { should be_an_instance_of DeadSimpleCMS::Util::Identifier::Dictionary }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|