comfortable_mexican_sofa 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Gemfile +2 -6
  2. data/Gemfile.lock +3 -4
  3. data/VERSION +1 -1
  4. data/app/controllers/cms_admin/base_controller.rb +1 -1
  5. data/app/controllers/cms_admin/layouts_controller.rb +2 -2
  6. data/app/controllers/cms_admin/pages_controller.rb +2 -2
  7. data/app/controllers/cms_admin/revisions_controller.rb +57 -0
  8. data/app/controllers/cms_admin/sites_controller.rb +2 -2
  9. data/app/controllers/cms_admin/snippets_controller.rb +2 -2
  10. data/app/models/cms/layout.rb +2 -0
  11. data/app/models/cms/page.rb +29 -9
  12. data/app/models/cms/revision.rb +13 -0
  13. data/app/models/cms/snippet.rb +2 -5
  14. data/app/views/cms_admin/layouts/_form.html.erb +0 -1
  15. data/app/views/cms_admin/layouts/edit.html.erb +1 -0
  16. data/app/views/cms_admin/pages/_form.html.erb +0 -1
  17. data/app/views/cms_admin/pages/edit.html.erb +1 -0
  18. data/app/views/cms_admin/revisions/show.html.erb +36 -0
  19. data/app/views/cms_admin/sites/_form.html.erb +0 -1
  20. data/app/views/cms_admin/snippets/_form.html.erb +0 -1
  21. data/app/views/cms_admin/snippets/edit.html.erb +1 -0
  22. data/app/views/layouts/cms_admin/_body.html.erb +4 -0
  23. data/app/views/layouts/cms_admin/_left.html.erb +9 -7
  24. data/comfortable_mexican_sofa.gemspec +19 -12
  25. data/config/initializers/comfortable_mexican_sofa.rb +5 -0
  26. data/config/routes.rb +13 -2
  27. data/db/migrate/01_create_cms.rb +11 -0
  28. data/db/migrate/upgrades/03_upgrade_to_1_2_0.rb +15 -0
  29. data/lib/comfortable_mexican_sofa.rb +3 -1
  30. data/lib/comfortable_mexican_sofa/configuration.rb +4 -0
  31. data/lib/comfortable_mexican_sofa/form_builder.rb +0 -1
  32. data/lib/comfortable_mexican_sofa/has_revisions.rb +64 -0
  33. data/lib/comfortable_mexican_sofa/http_auth.rb +1 -0
  34. data/lib/comfortable_mexican_sofa/version.rb +7 -0
  35. data/public/stylesheets/comfortable_mexican_sofa/content.css +42 -0
  36. data/public/stylesheets/comfortable_mexican_sofa/structure.css +31 -6
  37. data/public/stylesheets/comfortable_mexican_sofa/typography.css +8 -0
  38. data/test/fixtures/cms/revisions.yml +21 -0
  39. data/test/functional/cms_admin/layouts_controller_test.rb +2 -31
  40. data/test/functional/cms_admin/pages_controller_test.rb +7 -48
  41. data/test/functional/cms_admin/revisions_controller_test.rb +135 -0
  42. data/test/functional/cms_admin/sites_controller_test.rb +4 -29
  43. data/test/functional/cms_admin/snippets_controller_test.rb +2 -31
  44. data/test/test_helper.rb +1 -0
  45. data/test/unit/configuration_test.rb +5 -0
  46. data/test/unit/models/page_test.rb +0 -1
  47. data/test/unit/models/snippet_test.rb +0 -5
  48. data/test/unit/revisions_test.rb +185 -0
  49. metadata +18 -19
  50. data/config/initializers/mime_types.rb +0 -5
@@ -0,0 +1,135 @@
1
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
+
3
+ class CmsAdmin::RevisionsControllerTest < ActionController::TestCase
4
+
5
+ def test_get_index_for_layouts
6
+ get :index, :layout_id => cms_layouts(:default)
7
+ assert_response :redirect
8
+ assert_redirected_to :action => :show, :id => cms_revisions(:layout)
9
+ end
10
+
11
+ def test_get_index_for_pages
12
+ get :index, :page_id => cms_pages(:default)
13
+ assert_response :redirect
14
+ assert_redirected_to :action => :show, :id => cms_revisions(:page)
15
+ end
16
+
17
+ def test_get_index_for_snippets
18
+ get :index, :snippet_id => cms_snippets(:default)
19
+ assert_response :redirect
20
+ assert_redirected_to :action => :show, :id => cms_revisions(:snippet)
21
+ end
22
+
23
+ def test_get_index_for_snippets_with_no_revisions
24
+ Cms::Revision.delete_all
25
+ get :index, :snippet_id => cms_snippets(:default)
26
+ assert_response :redirect
27
+ assert_redirected_to :action => :show, :id => 0
28
+ end
29
+
30
+ def test_get_show_for_layout
31
+ get :show, :layout_id => cms_layouts(:default), :id => cms_revisions(:layout)
32
+ assert_response :success
33
+ assert assigns(:record)
34
+ assert assigns(:revision)
35
+ assert assigns(:record).is_a?(Cms::Layout)
36
+ assert_template :show
37
+ end
38
+
39
+ def test_get_show_for_page
40
+ get :show, :page_id => cms_pages(:default), :id => cms_revisions(:page)
41
+ assert_response :success
42
+ assert assigns(:record)
43
+ assert assigns(:revision)
44
+ assert assigns(:record).is_a?(Cms::Page)
45
+ assert_template :show
46
+ end
47
+
48
+ def test_get_show_for_snippet
49
+ get :show, :snippet_id => cms_snippets(:default), :id => cms_revisions(:snippet)
50
+ assert_response :success
51
+ assert assigns(:record)
52
+ assert assigns(:revision)
53
+ assert assigns(:record).is_a?(Cms::Snippet)
54
+ assert_template :show
55
+ end
56
+
57
+ def test_get_show_for_bad_type
58
+ get :show, :snippet_id => 'invalid', :id => cms_revisions(:snippet)
59
+ assert_response :redirect
60
+ assert_redirected_to cms_admin_path
61
+ assert_equal 'Record Not Found', flash[:error]
62
+ end
63
+
64
+ def test_get_show_for_layout_failure
65
+ get :show, :layout_id => cms_layouts(:default), :id => 'invalid'
66
+ assert_response :redirect
67
+ assert assigns(:record)
68
+ assert_redirected_to edit_cms_admin_layout_path(assigns(:record))
69
+ assert_equal 'Revision Not Found', flash[:error]
70
+ end
71
+
72
+ def test_get_show_for_page_failure
73
+ get :show, :page_id => cms_pages(:default), :id => 'invalid'
74
+ assert_response :redirect
75
+ assert assigns(:record)
76
+ assert_redirected_to edit_cms_admin_page_path(assigns(:record))
77
+ assert_equal 'Revision Not Found', flash[:error]
78
+ end
79
+
80
+ def test_get_show_for_snippet_failure
81
+ get :show, :snippet_id => cms_snippets(:default), :id => 'invalid'
82
+ assert_response :redirect
83
+ assert assigns(:record)
84
+ assert_redirected_to edit_cms_admin_snippet_path(assigns(:record))
85
+ assert_equal 'Revision Not Found', flash[:error]
86
+ end
87
+
88
+ def test_revert_for_layout
89
+ layout = cms_layouts(:default)
90
+
91
+ assert_difference 'layout.revisions.count' do
92
+ put :revert, :layout_id => layout, :id => cms_revisions(:layout)
93
+ assert_response :redirect
94
+ assert_redirected_to edit_cms_admin_layout_path(layout)
95
+ assert_equal 'Content Reverted', flash[:notice]
96
+
97
+ layout.reload
98
+ assert_equal 'revision {{cms:page:default_page_text}}', layout.content
99
+ assert_equal 'revision css', layout.css
100
+ assert_equal 'revision js', layout.js
101
+ end
102
+ end
103
+
104
+ def test_revert_for_page
105
+ page = cms_pages(:default)
106
+
107
+ assert_difference 'page.revisions.count' do
108
+ put :revert, :page_id => page, :id => cms_revisions(:page)
109
+ assert_response :redirect
110
+ assert_redirected_to edit_cms_admin_page_path(page)
111
+ assert_equal 'Content Reverted', flash[:notice]
112
+
113
+ page.reload
114
+ assert_equal [
115
+ { :label => 'default_field_text', :content => 'revision field content' },
116
+ { :label => 'default_page_text', :content => 'revision page content' }
117
+ ], page.blocks_attributes
118
+ end
119
+ end
120
+
121
+ def test_revert_for_snippet
122
+ snippet = cms_snippets(:default)
123
+
124
+ assert_difference 'snippet.revisions.count' do
125
+ put :revert, :snippet_id => snippet, :id => cms_revisions(:snippet)
126
+ assert_response :redirect
127
+ assert_redirected_to edit_cms_admin_snippet_path(snippet)
128
+ assert_equal 'Content Reverted', flash[:notice]
129
+
130
+ snippet.reload
131
+ assert_equal 'revision content', snippet.content
132
+ end
133
+ end
134
+
135
+ end
@@ -41,26 +41,15 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase
41
41
  assert_equal 'Site not found', flash[:error]
42
42
  end
43
43
 
44
- def test_create_with_commit
45
- assert_difference 'Cms::Site.count' do
46
- post :create, :cms_site => {
47
- :label => 'Test Site',
48
- :hostname => 'test.site.local'
49
- }, :commit => 'Create Site'
50
- assert_response :redirect
51
- assert_redirected_to :action => :index
52
- assert_equal 'Site created', flash[:notice]
53
- end
54
- end
55
-
56
- def test_create_without_commit
44
+ def test_create
57
45
  assert_difference 'Cms::Site.count' do
58
46
  post :create, :cms_site => {
59
47
  :label => 'Test Site',
60
48
  :hostname => 'test.site.local'
61
49
  }
62
50
  assert_response :redirect
63
- assert_redirected_to :action => :edit, :id => Cms::Site.last
51
+ site = Cms::Site.last
52
+ assert_redirected_to :action => :edit, :id => site
64
53
  assert_equal 'Site created', flash[:notice]
65
54
  end
66
55
  end
@@ -74,21 +63,7 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase
74
63
  end
75
64
  end
76
65
 
77
- def test_update_with_commit
78
- site = cms_sites(:default)
79
- put :update, :id => site, :cms_site => {
80
- :label => 'New Site',
81
- :hostname => 'new.site.local'
82
- }, :commit => 'Update Site'
83
- assert_response :redirect
84
- assert_redirected_to :action => :index
85
- assert_equal 'Site updated', flash[:notice]
86
- site.reload
87
- assert_equal 'New Site', site.label
88
- assert_equal 'new.site.local', site.hostname
89
- end
90
-
91
- def test_update_without_commit
66
+ def test_update
92
67
  site = cms_sites(:default)
93
68
  put :update, :id => site, :cms_site => {
94
69
  :label => 'New Site',
@@ -40,22 +40,7 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
40
40
  assert_equal 'Snippet not found', flash[:error]
41
41
  end
42
42
 
43
- def test_create_with_commit
44
- assert_difference 'Cms::Snippet.count' do
45
- post :create, :cms_snippet => {
46
- :label => 'Test Snippet',
47
- :slug => 'test-snippet',
48
- :content => 'Test Content'
49
- }, :commit => 'Create Snippet'
50
- assert_response :redirect
51
- snippet = Cms::Snippet.last
52
- assert_equal cms_sites(:default), snippet.site
53
- assert_redirected_to :action => :index
54
- assert_equal 'Snippet created', flash[:notice]
55
- end
56
- end
57
-
58
- def test_create_without_commit
43
+ def test_create
59
44
  assert_difference 'Cms::Snippet.count' do
60
45
  post :create, :cms_snippet => {
61
46
  :label => 'Test Snippet',
@@ -79,21 +64,7 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
79
64
  end
80
65
  end
81
66
 
82
- def test_update_with_commit
83
- snippet = cms_snippets(:default)
84
- put :update, :id => snippet, :cms_snippet => {
85
- :label => 'New-Snippet',
86
- :content => 'New Content'
87
- }, :commit => 'Update Snippet'
88
- assert_response :redirect
89
- assert_redirected_to :action => :index
90
- assert_equal 'Snippet updated', flash[:notice]
91
- snippet.reload
92
- assert_equal 'New-Snippet', snippet.label
93
- assert_equal 'New Content', snippet.content
94
- end
95
-
96
- def test_update_without_commit
67
+ def test_update
97
68
  snippet = cms_snippets(:default)
98
69
  put :update, :id => snippet, :cms_snippet => {
99
70
  :label => 'New-Snippet',
data/test/test_helper.rb CHANGED
@@ -24,6 +24,7 @@ class ActiveSupport::TestCase
24
24
  config.enable_caching = true
25
25
  config.enable_fixtures = false
26
26
  config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
27
+ config.revisions_limit = 25
27
28
  end
28
29
  ComfortableMexicanSofa::HttpAuth.username = 'username'
29
30
  ComfortableMexicanSofa::HttpAuth.password = 'password'
@@ -14,6 +14,7 @@ class ConfigurationTest < ActiveSupport::TestCase
14
14
  assert_equal true, config.enable_caching
15
15
  assert_equal false, config.enable_fixtures
16
16
  assert_equal File.expand_path('db/cms_fixtures', Rails.root), config.fixtures_path
17
+ assert_equal 25, config.revisions_limit
17
18
  end
18
19
 
19
20
  def test_initialization_overrides
@@ -21,4 +22,8 @@ class ConfigurationTest < ActiveSupport::TestCase
21
22
  assert_equal 'New Title', ComfortableMexicanSofa.configuration.cms_title
22
23
  end
23
24
 
25
+ def test_version
26
+ assert ComfortableMexicanSofa::VERSION
27
+ end
28
+
24
29
  end
@@ -157,7 +157,6 @@ class CmsPageTest < ActiveSupport::TestCase
157
157
  assert_equal page.blocks.count, page.blocks_attributes.size
158
158
  assert_equal 'default_field_text', page.blocks_attributes.first[:label]
159
159
  assert_equal 'default_field_text_content', page.blocks_attributes.first[:content]
160
- assert page.blocks_attributes.first[:id]
161
160
  end
162
161
 
163
162
  def test_content_caching
@@ -15,11 +15,6 @@ class CmsSnippetTest < ActiveSupport::TestCase
15
15
  assert_has_errors_on snippet, [:label, :slug]
16
16
  end
17
17
 
18
- def test_method_content
19
- assert_equal cms_snippets(:default).content, Cms::Snippet.content_for('default')
20
- assert_equal '', Cms::Snippet.content_for('nonexistent_snippet')
21
- end
22
-
23
18
  def test_update_forces_page_content_reload
24
19
  snippet = cms_snippets(:default)
25
20
  page = cms_pages(:default)
@@ -0,0 +1,185 @@
1
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
2
+
3
+ class RevisionsTest < ActiveSupport::TestCase
4
+
5
+ def test_fixtures_validity
6
+ assert_equal ({
7
+ 'content' => 'revision {{cms:page:default_page_text}}',
8
+ 'css' => 'revision css',
9
+ 'js' => 'revision js' }), cms_revisions(:layout).data
10
+
11
+ assert_equal ({'blocks_attributes' => [
12
+ { 'label' => 'default_page_text', 'content' => 'revision page content' },
13
+ { 'label' => 'default_field_text', 'content' => 'revision field content' }
14
+ ]}), cms_revisions(:page).data
15
+
16
+ assert_equal ({
17
+ 'content' => 'revision content'
18
+ }), cms_revisions(:snippet).data
19
+ end
20
+
21
+ def test_init_for_layouts
22
+ assert_equal ['content', 'css', 'js'], cms_layouts(:default).revision_fields
23
+ end
24
+
25
+ def test_init_for_pages
26
+ assert_equal ['blocks_attributes'], cms_pages(:default).revision_fields
27
+ end
28
+
29
+ def test_init_for_snippets
30
+ assert_equal ['content'], cms_snippets(:default).revision_fields
31
+ end
32
+
33
+ def test_creation_for_layout
34
+ layout = cms_layouts(:default)
35
+ old_attributes = layout.attributes.slice('content', 'css', 'js')
36
+
37
+ assert_difference 'layout.revisions.count' do
38
+ layout.update_attributes!(
39
+ :content => 'new {{cms:page:content}}',
40
+ :js => 'new js'
41
+ )
42
+ layout.reload
43
+ assert_equal 2, layout.revisions.count
44
+ revision = layout.revisions.first
45
+ assert_equal old_attributes, revision.data
46
+ end
47
+ end
48
+
49
+ def test_creation_for_layout_ignore
50
+ layout = cms_layouts(:default)
51
+ assert_no_difference 'layout.revisions.count' do
52
+ layout.update_attribute(:label, 'new label')
53
+ end
54
+ end
55
+
56
+ def test_creation_for_page
57
+ page = cms_pages(:default)
58
+
59
+ assert_difference 'page.revisions.count' do
60
+ page.update_attributes!(
61
+ :blocks_attributes => [
62
+ { :label => 'default_page_text',
63
+ :content => 'new content' }
64
+ ]
65
+ )
66
+ page.reload
67
+ assert_equal 2, page.revisions.count
68
+ revision = page.revisions.first
69
+ assert_equal ({
70
+ 'blocks_attributes' => [
71
+ { :label => 'default_field_text',
72
+ :content => 'default_field_text_content' },
73
+ { :label => 'default_page_text',
74
+ :content => "default_page_text_content_a\n{{cms:snippet:default}}\ndefault_page_text_content_b" }]
75
+ }), revision.data
76
+ end
77
+ end
78
+
79
+ def test_creation_for_page_ignore
80
+ page = cms_pages(:default)
81
+ assert_no_difference 'page.revisions.count' do
82
+ page.update_attribute(:label, 'new label')
83
+ end
84
+ end
85
+
86
+ def test_creation_for_snippet
87
+ snippet = cms_snippets(:default)
88
+ old_attributes = snippet.attributes.slice('content')
89
+
90
+ assert_difference 'snippet.revisions.count' do
91
+ snippet.update_attribute(:content, 'new content')
92
+ snippet.reload
93
+ assert_equal 2, snippet.revisions.count
94
+ revision = snippet.revisions.first
95
+ assert_equal old_attributes, revision.data
96
+ end
97
+ end
98
+
99
+ def test_creation_for_snippet_ignore
100
+ snippet = cms_snippets(:default)
101
+ assert_no_difference 'snippet.revisions.count' do
102
+ snippet.update_attribute(:label, 'new label')
103
+ end
104
+ end
105
+
106
+ def test_creation_for_new_record
107
+ assert_difference 'Cms::Snippet.count' do
108
+ assert_no_difference 'Cms::Revision.count' do
109
+ snippet = cms_sites(:default).snippets.create!(
110
+ :label => 'test snippet',
111
+ :slug => 'test_snippet',
112
+ :content => 'test content'
113
+ )
114
+ assert_equal 0, snippet.revisions.count
115
+ end
116
+ end
117
+ end
118
+
119
+ def test_restore_from_revision_for_layout
120
+ layout = cms_layouts(:default)
121
+ revision = cms_revisions(:layout)
122
+
123
+ assert_difference 'layout.revisions.count' do
124
+ layout.restore_from_revision(revision)
125
+ layout.reload
126
+ assert_equal 'revision {{cms:page:default_page_text}}', layout.content
127
+ assert_equal 'revision css', layout.css
128
+ assert_equal 'revision js', layout.js
129
+ end
130
+ end
131
+
132
+ def test_restore_from_revision_for_page
133
+ page = cms_pages(:default)
134
+ revision = cms_revisions(:page)
135
+
136
+ assert_difference 'page.revisions.count' do
137
+ page.restore_from_revision(revision)
138
+ page.reload
139
+ assert_equal [
140
+ { :label => 'default_field_text', :content => 'revision field content' },
141
+ { :label => 'default_page_text', :content => 'revision page content' }
142
+ ], page.blocks_attributes
143
+ end
144
+ end
145
+
146
+ def test_restore_from_revision_for_snippet
147
+ snippet = cms_snippets(:default)
148
+ revision = cms_revisions(:snippet)
149
+
150
+ assert_difference 'snippet.revisions.count' do
151
+ snippet.restore_from_revision(revision)
152
+ snippet.reload
153
+ assert_equal 'revision content', snippet.content
154
+ end
155
+ end
156
+
157
+ def test_restore_from_revision_with_wrong_revision_type
158
+ snippet = cms_snippets(:default)
159
+ revision = cms_revisions(:layout)
160
+
161
+ assert_no_difference 'snippet.revisions.count' do
162
+ snippet.restore_from_revision(revision)
163
+ snippet.reload
164
+ assert_equal 'default_snippet_content', snippet.content
165
+ end
166
+ end
167
+
168
+ def test_creation_with_limit
169
+ ComfortableMexicanSofa.config.revisions_limit = 1
170
+ snippet = cms_snippets(:default)
171
+ revision = cms_revisions(:snippet)
172
+
173
+ assert_equal 1, snippet.revisions.count
174
+
175
+ assert_no_difference 'snippet.revisions.count' do
176
+ snippet.update_attribute(:content, 'new content')
177
+ assert_nil Cms::Revision.find_by_id(revision.id)
178
+
179
+ snippet.reload
180
+ revision = snippet.revisions.first
181
+ assert_equal ({ 'content' => 'default_snippet_content' }), revision.data
182
+ end
183
+ end
184
+
185
+ end