kuhsaft 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/README +9 -0
  2. data/app/controllers/kuhsaft/admin/admin_controller.rb +18 -0
  3. data/app/controllers/kuhsaft/admin/assets_controller.rb +1 -4
  4. data/app/controllers/kuhsaft/admin/pages_controller.rb +17 -17
  5. data/app/models/kuhsaft/localized_page.rb +22 -3
  6. data/app/models/kuhsaft/page.rb +22 -18
  7. data/app/models/kuhsaft/page_part.rb +1 -1
  8. data/app/models/kuhsaft/page_part/content.rb +55 -0
  9. data/app/models/kuhsaft/page_part/markdown.rb +8 -0
  10. data/app/models/kuhsaft/publish_state.rb +29 -0
  11. data/app/stylesheets/kuhsaft/admin/partials/_generic.sass +29 -10
  12. data/app/stylesheets/kuhsaft/admin/partials/_pages.sass +6 -2
  13. data/app/views/kuhsaft/admin/kuhsaft/page_part/markdowns/_markdown.html.haml +1 -0
  14. data/app/views/kuhsaft/admin/pages/_form.html.haml +22 -11
  15. data/app/views/kuhsaft/admin/pages/edit.html.haml +7 -1
  16. data/app/views/kuhsaft/admin/pages/index.html.haml +0 -13
  17. data/app/views/kuhsaft/admin/pages/new.html.haml +3 -1
  18. data/app/views/layouts/kuhsaft/admin.html.haml +3 -1
  19. data/config/initializers/page_parts.rb +16 -0
  20. data/config/locales/kuhsaft.en.yml +2 -0
  21. data/config/routes.rb +6 -1
  22. data/kuhsaft.gemspec +4 -4
  23. data/lib/generators/kuhsaft/install/migrations_generator.rb +5 -1
  24. data/lib/kuhsaft/version.rb +1 -1
  25. data/lib/templates/kuhsaft/install/add_fulltext_to_localized_page.rb +9 -0
  26. data/lib/templates/kuhsaft/install/add_page_type_to_localized_pages.rb +9 -0
  27. data/lib/templates/kuhsaft/install/add_published_at_to_localized_pages.rb +9 -0
  28. data/lib/templates/kuhsaft/install/add_type_to_page_part_contents.rb +9 -0
  29. data/public/javascripts/kuhsaft/admin/application.js +17 -0
  30. data/public/javascripts/kuhsaft/admin/jquery-ui-1.8.12.custom.min.js +192 -0
  31. data/spec/controllers/admin_pages_controller_spec.rb +33 -6
  32. data/spec/dummy/config/database.yml +2 -2
  33. data/spec/dummy/config/locales/en.yml +3 -1
  34. data/spec/factories.rb +0 -9
  35. data/spec/models/localized_page_spec.rb +103 -15
  36. data/spec/models/page_part_content_spec.rb +59 -17
  37. data/spec/models/page_part_spec.rb +1 -1
  38. data/spec/models/page_spec.rb +34 -29
  39. data/spec/models/publish_state_spec.rb +45 -0
  40. data/spec/routing/pages_routing_spec.rb +28 -21
  41. metadata +38 -21
  42. data/app/models/kuhsaft/page_parts/base.rb +0 -26
  43. data/app/models/kuhsaft/page_parts/content.rb +0 -8
  44. data/app/models/kuhsaft/page_parts/markdown.rb +0 -7
  45. data/public/javascripts/kuhsaft/admin/jquery-ui-1.8.10.custom.min.js +0 -110
@@ -12,8 +12,8 @@ development:
12
12
  test:
13
13
  adapter: sqlite3
14
14
  database: db/test.sqlite3
15
- pool: 5
16
- timeout: 5000
15
+ pool: 50
16
+ timeout: 25000
17
17
 
18
18
  production:
19
19
  adapter: sqlite3
@@ -2,4 +2,6 @@
2
2
  # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
3
 
4
4
  en:
5
- hello: "Hello world"
5
+ unpublished: "unpublished"
6
+ published: "published"
7
+ published_at: "publish on date"
@@ -1,9 +1,3 @@
1
- Factory.define :page_part, :class => Kuhsaft::PagePart::Content do |p|
2
- p.position 1
3
- p.content Kuhsaft::PagePart::Markdown.new(:text => 'h1. Hello world!')
4
- p.association :localized_page
5
- end
6
-
7
1
  Factory.define :localized_page, :class => Kuhsaft::LocalizedPage do |p|
8
2
  p.locale 'en'
9
3
  p.title 'English title'
@@ -11,9 +5,6 @@ Factory.define :localized_page, :class => Kuhsaft::LocalizedPage do |p|
11
5
  p.body 'hi'
12
6
  p.url ''
13
7
  p.association :page
14
- p.after_create do |page|
15
- page.page_parts << Factory.build(:page_part, :localized_page => page)
16
- end
17
8
  end
18
9
 
19
10
  Factory.define :page, :class => Kuhsaft::Page do |p|
@@ -1,9 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Kuhsaft::LocalizedPage do
4
-
5
4
  before :each do
6
- @localized_page = Factory.build :localized_page
5
+ @localized_page = Factory.create(:localized_page)
7
6
  end
8
7
 
9
8
  it 'should have a symbolized locale' do
@@ -11,7 +10,11 @@ describe Kuhsaft::LocalizedPage do
11
10
  end
12
11
 
13
12
  it 'should be published' do
14
- Factory.create(:localized_page).published?.should be_true
13
+ @localized_page.published?.should be_true
14
+ end
15
+
16
+ it 'should have a fulltext field' do
17
+ @localized_page.should respond_to(:fulltext)
15
18
  end
16
19
 
17
20
  it 'should not be published when set to false' do
@@ -34,35 +37,120 @@ describe Kuhsaft::LocalizedPage do
34
37
  end
35
38
 
36
39
  it 'should generate the slug from the title' do
37
- Factory.create(:localized_page).slug.should == @localized_page.title.parameterize
40
+ @localized_page.slug.should eq(@localized_page.title.parameterize)
41
+ end
42
+
43
+ it 'should have page_parts' do
44
+ @localized_page.should respond_to(:page_parts)
38
45
  end
39
46
 
40
47
  it 'should not generate the slug if the user has set it' do
41
48
  Factory.create(:localized_page, :slug => 'my-slug').slug.should == 'my-slug'
42
49
  end
43
50
 
44
- it 'should have pageparts' do
45
- Factory.create(:localized_page).page_parts.count.should be(1)
51
+ after :each do
52
+ @localized_page.destroy
46
53
  end
47
54
 
48
- it 'should delegate childs to it\'s page' do
49
- @localized_page.childs.should == @localized_page.page.childs
55
+ describe 'page_type' do
56
+ it 'should have a page_type' do
57
+ @localized_page.should respond_to(:page_type)
58
+ end
59
+
60
+ it 'should generate the url with an empty page_type' do
61
+ page = Factory.create :page
62
+ page.translation.url.should eq('en/english-title')
63
+ end
64
+
65
+ it 'should take the users url with a "redirect" page_type' do
66
+ page = Factory.create :page
67
+ page.translation.page_type = 'redirect'
68
+ page.translation.url = '/en/news'
69
+ page.save
70
+ page.translation.url.should eq('/en/news')
71
+ end
50
72
  end
51
73
 
52
74
  describe 'validations' do
53
-
54
- before :each do
55
- @page = Factory.create :page
56
- @page.title = nil
57
- @page.slug = nil
75
+ before do
76
+ @localized_page = Factory.create :localized_page
77
+ @localized_page.title = nil
78
+ @localized_page.slug = nil
58
79
  end
59
80
 
60
81
  it 'should have a title' do
61
- @page.translation.should have(1).error_on(:title)
82
+ @localized_page.should have(1).error_on(:title)
62
83
  end
63
84
 
64
85
  it 'should have a slug' do
65
- @page.translation.should have(1).error_on(:slug)
86
+ @localized_page.should have(1).error_on(:slug)
87
+ end
88
+
89
+ after do
90
+ @localized_page.destroy
91
+ end
92
+ end
93
+
94
+ describe 'fulltext' do
95
+ before do
96
+ @page = Factory.create :page
97
+ @page.translation.keywords = 'key words'
98
+ @page.translation.description = 'descrip tion'
99
+ @page.translation.title = 'my title'
100
+ @page.translation.page_parts << Kuhsaft::PagePart::Markdown.new(:text => 'oh la la1')
101
+ @page.translation.page_parts << Kuhsaft::PagePart::Markdown.new(:text => 'oh la la2')
102
+ @page.translation.page_parts << Kuhsaft::PagePart::Markdown.new(:text => 'oh la la3')
103
+ @page.translation.page_parts << Kuhsaft::PagePart::Markdown.new(:text => nil)
104
+ @page.save
105
+ end
106
+
107
+ it 'should collect the fulltext when saved' do
108
+ @page.translation.should_receive(:collect_fulltext)
109
+ @page.save
110
+ end
111
+
112
+ it 'should contain the title' do
113
+ @page.fulltext.should include('my title')
114
+ end
115
+
116
+ it 'should contain the keywords' do
117
+ @page.fulltext.should include('key words')
118
+ end
119
+
120
+ it 'should contain the description' do
121
+ @page.fulltext.should include('descrip tion')
122
+ end
123
+
124
+ it 'should contain the page part content' do
125
+ @page.fulltext.should include('oh la la')
126
+ end
127
+
128
+ it 'should convert all data to strings' do
129
+ expect { @page.translation.collect_fulltext }.to_not raise_error
130
+ end
131
+ end
132
+
133
+ describe 'search' do
134
+ before do
135
+ Factory.create :page
136
+ Factory.create :page
137
+ Factory.create :page
138
+ end
139
+
140
+ it 'should find any containing the search term' do
141
+ Kuhsaft::LocalizedPage.search('hi').should have_at_least(0).items
142
+ end
143
+
144
+ it 'should find with "English Title"' do
145
+ Kuhsaft::LocalizedPage.search('English Title').should have_at_least(1).item
146
+ end
147
+
148
+ it 'should only find results with the current locale' do
149
+ Kuhsaft::LocalizedPage.search('English Title').should be_all { |p| p.locale == Kuhsaft::Page.current_translation_locale }
150
+ end
151
+
152
+ it 'should only find published results' do
153
+ Kuhsaft::LocalizedPage.search('English Title').should be_all { |p| p.published? == true }
66
154
  end
67
155
  end
68
156
  end
@@ -1,22 +1,64 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Kuhsaft::PagePart::Content do
4
-
5
- before :each do
6
- @page_part = Factory.build :page_part
7
- end
8
-
9
- it 'should serialize it\'s content when saved' do
10
- @page_part.content.should_receive(:to_yaml)
11
- @page_part.save
12
- end
13
-
14
- it 'should deserialize it\'s content when loaded' do
15
- @page_part.save
16
- @page_part.content.should be_a(Kuhsaft::PagePart::Base)
3
+ describe 'PagePart' do
4
+ describe 'Content' do
5
+ before do
6
+ @content = Kuhsaft::PagePart::Content.new
7
+ end
8
+
9
+ it 'should belong to a LocalizedPage' do
10
+ @content.should respond_to(:localized_page)
11
+ end
12
+
13
+ it 'should have a content to store serialized data' do
14
+ @content.should respond_to(:content)
15
+ end
16
+
17
+ context 'class' do
18
+ it 'should keep a list of the serializeable attributes' do
19
+ Kuhsaft::PagePart::Content.serializeable_attributes.should be_a(Array)
20
+ end
21
+
22
+ it 'should keep a list of searchable attributes' do
23
+ Kuhsaft::PagePart::Content.searchable_attributes.should be_a(Array)
24
+ end
25
+
26
+ it 'should have a list of page_part_types' do
27
+ Kuhsaft::PagePart::Content.page_part_types.should be_all { |p| p.superclass.should eq Kuhsaft::PagePart::Content }
28
+ end
29
+
30
+ it 'should have the Markdown PagePart by default' do
31
+ Kuhsaft::PagePart::Content.descendants.should include(Kuhsaft::PagePart::Markdown)
32
+ end
33
+
34
+ it 'should convert to_name' do
35
+ Kuhsaft::PagePart::Markdown.to_name.should eq('Markdown')
36
+ end
37
+ end
17
38
  end
18
39
 
19
- it 'should have a text in the default markdown PagePart' do
20
- @page_part.content.text.should == 'h1. Hello world!'
40
+ describe 'Markdown' do
41
+ before do
42
+ @m = Kuhsaft::PagePart::Markdown.new
43
+ end
44
+
45
+ it 'should have text' do
46
+ @m.should respond_to(:text)
47
+ end
48
+
49
+ it 'should have searchable text' do
50
+ Kuhsaft::PagePart::Markdown.searchable_attributes.should include(:text)
51
+ end
52
+
53
+ it 'should store text' do
54
+ @m.text = 'hi'
55
+ @m.text.should eq('hi')
56
+ end
57
+
58
+ it 'should restore the serialized attributes when loaded' do
59
+ m = Kuhsaft::PagePart::Markdown.create(:text => 'hi')
60
+ m2 = Kuhsaft::PagePart::Markdown.find(m.id)
61
+ m2.text.should eq('hi')
62
+ end
21
63
  end
22
- end
64
+ end
@@ -14,4 +14,4 @@ describe Kuhsaft::PagePart do
14
14
  lambda { Kuhsaft::PagePart.all.each { |p| p.to_s.camelize.constantize } }.should_not raise_error NameError
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -2,6 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe Kuhsaft::Page do
4
4
 
5
+ before do
6
+ set_lang :en
7
+ end
8
+
9
+ after do
10
+ reset_lang
11
+ end
12
+
5
13
  before :each do
6
14
  destroy_all_pages
7
15
  @page = Factory.create :page
@@ -111,11 +119,19 @@ describe Kuhsaft::Page do
111
119
  page = Factory.create :page
112
120
  child = Factory.create :page
113
121
  page.childs << child
114
- page.body = nil
122
+ page.translation.body = nil
115
123
  page.save
116
124
  page.link.should == child.link
117
125
  end
118
126
 
127
+ it 'should not modify the url when it\'s a redirect' do
128
+ page = Factory.create :page
129
+ page.translation.page_type = 'redirect'
130
+ page.translation.url = '/en/news'
131
+ page.save
132
+ page.link.should eq('/en/news')
133
+ end
134
+
119
135
  it 'should find its translated content by url' do
120
136
  destroy_all_pages
121
137
  page = Factory.create(:page)
@@ -140,38 +156,27 @@ describe Kuhsaft::Page do
140
156
  Kuhsaft::Page.translation_locales.first.should be(:de)
141
157
  end
142
158
 
143
- describe 'should delegate property' do
144
- it 'should have a localized_page to delegate to' do
145
- @page.translation.should be_a(Kuhsaft::LocalizedPage)
146
- end
147
-
148
- it 'should delegate the title to the translation' do
149
- @page.title = 'Hello'
150
- @page.translation.title.should == 'Hello'
151
- end
152
-
153
- it 'should delegate the slug to the translation' do
154
- @page.slug = 'my-slug'
155
- @page.translation.slug.should == 'my-slug'
156
- end
157
-
158
- it 'should delegate the url to the translation' do
159
- @page.url.should == @page.translation.url
160
- end
161
-
162
- it 'should delegate the keywords to the translation' do
163
- @page.keywords = 'my keywords are superb'
164
- @page.translation.keywords.should == 'my keywords are superb'
159
+ it 'should have a translation' do
160
+ @page.translation.should be_a(Kuhsaft::LocalizedPage)
161
+ end
162
+
163
+ it 'accepts a page_part_type to determine which page_part needs to be added' do
164
+ @page.should respond_to(:page_part_type)
165
+ end
166
+
167
+ describe 'should delegate' do
168
+ it 'slug, title, keywords and description to the translation' do
169
+ [:slug, :title, :keywords, :description].each do |attr|
170
+ @page.send(attr).should eq(@page.translation.send(attr))
171
+ end
165
172
  end
166
173
 
167
- it 'should delegate the description to the translation' do
168
- @page.description = 'my description'
169
- @page.translation.description.should == 'my description'
174
+ it 'url to the translation' do
175
+ @page.url.should eq(@page.translation.url)
170
176
  end
171
177
 
172
- it 'should delegate the locale to the translation' do
173
- @page.locale = 'de'
174
- @page.translation.locale.should == :de
178
+ it 'locale to the translation' do
179
+ @page.locale.should be(@page.translation.locale)
175
180
  end
176
181
  end
177
182
  end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kuhsaft::PublishState do
4
+ context 'unpublished' do
5
+ before do
6
+ @publish_state = Kuhsaft::PublishState.new(:name => 'unpublished', :value => Kuhsaft::PublishState::UNPUBLISHED)
7
+ end
8
+
9
+ it 'should be UNPUBLISHED' do
10
+ @publish_state.value.should be(Kuhsaft::PublishState::UNPUBLISHED)
11
+ end
12
+
13
+ it 'should have a translated name' do
14
+ @publish_state.human_name.should eq(I18n.translate('unpublished'))
15
+ end
16
+ end
17
+
18
+ context 'published' do
19
+ before do
20
+ @publish_state = Kuhsaft::PublishState.new(:name => 'published', :value => Kuhsaft::PublishState::PUBLISHED)
21
+ end
22
+
23
+ it 'should be PUBLISHED' do
24
+ @publish_state.value.should be(Kuhsaft::PublishState::PUBLISHED)
25
+ end
26
+
27
+ it 'should have a translated name' do
28
+ @publish_state.human_name.should eq(I18n.translate('published'))
29
+ end
30
+ end
31
+
32
+ context 'published_at' do
33
+ before do
34
+ @publish_state = Kuhsaft::PublishState.new(:name => 'published_at', :value => Kuhsaft::PublishState::PUBLISHED_AT)
35
+ end
36
+
37
+ it 'should be PUBLISHED_AT' do
38
+ @publish_state.value.should be(Kuhsaft::PublishState::PUBLISHED_AT)
39
+ end
40
+
41
+ it 'should have a translated name' do
42
+ @publish_state.human_name.should eq(I18n.translate('published_at'))
43
+ end
44
+ end
45
+ end
@@ -11,56 +11,63 @@ describe 'routing to Kuhsaft::PagesController' do
11
11
  end
12
12
 
13
13
  describe 'routing to Kuhsaft::Admin::PagesController' do
14
- it 'routes /admin/pages to admin/pages#index' do
15
- { :get => '/admin/pages' }.should route_to(
14
+ it 'routes /en/admin/pages to admin/pages#index' do
15
+ { :get => '/en/admin/pages' }.should route_to(
16
16
  :controller => 'kuhsaft/admin/pages',
17
- :action => 'index'
17
+ :action => 'index',
18
+ :locale => 'en'
18
19
  )
19
20
  end
20
21
 
21
- it 'routes POST /admin/pages to admin/pages#create' do
22
- { :post => '/admin/pages' }.should route_to(
22
+ it 'routes POST /en/admin/pages to admin/pages#create' do
23
+ { :post => '/en/admin/pages' }.should route_to(
23
24
  :controller => 'kuhsaft/admin/pages',
24
- :action => 'create'
25
+ :action => 'create',
26
+ :locale => 'en'
25
27
  )
26
28
  end
27
29
 
28
- it 'routes PUT /admin/pages/:id to admin/pages#update' do
29
- { :put => '/admin/pages/1' }.should route_to(
30
+ it 'routes PUT /en/admin/pages/:id to admin/pages#update' do
31
+ { :put => '/en/admin/pages/1' }.should route_to(
30
32
  :controller => 'kuhsaft/admin/pages',
31
33
  :action => 'update',
32
- :id => '1'
34
+ :id => '1',
35
+ :locale => 'en'
33
36
  )
34
37
  end
35
38
 
36
- it 'routes DELETE /admin/pages/:id to admin/pages#destroy' do
37
- { :delete => '/admin/pages/1' }.should route_to(
39
+ it 'routes DELETE /en/admin/pages/:id to admin/pages#destroy' do
40
+ { :delete => '/en/admin/pages/1' }.should route_to(
38
41
  :controller => 'kuhsaft/admin/pages',
39
42
  :action => 'destroy',
40
- :id => '1'
43
+ :id => '1',
44
+ :locale => 'en'
41
45
  )
42
46
  end
43
47
 
44
- it 'routes /admin/pages/:id to admin/pages#show' do
45
- { :get => '/admin/pages/1' }.should route_to(
48
+ it 'routes /en/admin/pages/:id to admin/pages#show' do
49
+ { :get => '/en/admin/pages/1' }.should route_to(
46
50
  :controller => 'kuhsaft/admin/pages',
47
51
  :action => 'show',
48
- :id => '1'
52
+ :id => '1',
53
+ :locale => 'en'
49
54
  )
50
55
  end
51
56
 
52
- it 'routes /admin/pages/new to admin/pages#new' do
53
- { :get => '/admin/pages/new' }.should route_to(
57
+ it 'routes /en/admin/pages/new to admin/pages#new' do
58
+ { :get => '/en/admin/pages/new' }.should route_to(
54
59
  :controller => 'kuhsaft/admin/pages',
55
- :action => 'new'
60
+ :action => 'new',
61
+ :locale => 'en'
56
62
  )
57
63
  end
58
64
 
59
- it 'routes /admin/pages/:id/edit to admin/pages#edit' do
60
- { :get => '/admin/pages/1/edit' }.should route_to(
65
+ it 'routes /en/admin/pages/:id/edit to admin/pages#edit' do
66
+ { :get => '/en/admin/pages/1/edit' }.should route_to(
61
67
  :controller => 'kuhsaft/admin/pages',
62
68
  :action => 'edit',
63
- :id => '1'
69
+ :id => '1',
70
+ :locale => 'en'
64
71
  )
65
72
  end
66
73
  end