rails_wordpress 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/Guardfile +77 -0
  3. data/LICENSE +22 -0
  4. data/Rakefile +28 -0
  5. data/app/assets/javascripts/wordpress/application.js +13 -0
  6. data/app/assets/stylesheets/wordpress/application.css +15 -0
  7. data/app/controllers/wordpress/application_controller.rb +4 -0
  8. data/app/helpers/wordpress/application_helper.rb +4 -0
  9. data/app/models/wordpress/attachment.rb +7 -0
  10. data/app/models/wordpress/category.rb +18 -0
  11. data/app/models/wordpress/link_category.rb +4 -0
  12. data/app/models/wordpress/page.rb +4 -0
  13. data/app/models/wordpress/post.rb +4 -0
  14. data/app/models/wordpress/post_tag.rb +14 -0
  15. data/app/models/wordpress/relationship.rb +26 -0
  16. data/app/models/wordpress/revision.rb +4 -0
  17. data/app/models/wordpress/taxonomy.rb +56 -0
  18. data/app/models/wordpress/term.rb +19 -0
  19. data/app/models/wordpress/user.rb +7 -0
  20. data/app/models/wordpress/wp_post.rb +195 -0
  21. data/app/views/layouts/wordpress/application.html.erb +14 -0
  22. data/config/routes.rb +2 -0
  23. data/lib/rails_wordpress/engine.rb +18 -0
  24. data/lib/rails_wordpress/version.rb +3 -0
  25. data/lib/rails_wordpress.rb +4 -0
  26. data/lib/tasks/word_press_tasks.rake +4 -0
  27. data/spec/dummy/README.rdoc +28 -0
  28. data/spec/dummy/Rakefile +6 -0
  29. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  30. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  31. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  32. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  33. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/spec/dummy/bin/bundle +3 -0
  35. data/spec/dummy/bin/rails +4 -0
  36. data/spec/dummy/bin/rake +4 -0
  37. data/spec/dummy/bin/setup +29 -0
  38. data/spec/dummy/config/application.rb +26 -0
  39. data/spec/dummy/config/boot.rb +5 -0
  40. data/spec/dummy/config/database.yml +24 -0
  41. data/spec/dummy/config/environment.rb +5 -0
  42. data/spec/dummy/config/environments/development.rb +41 -0
  43. data/spec/dummy/config/environments/production.rb +79 -0
  44. data/spec/dummy/config/environments/test.rb +42 -0
  45. data/spec/dummy/config/initializers/assets.rb +11 -0
  46. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  47. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  48. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  49. data/spec/dummy/config/initializers/inflections.rb +16 -0
  50. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  51. data/spec/dummy/config/initializers/session_store.rb +3 -0
  52. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/spec/dummy/config/locales/en.yml +23 -0
  54. data/spec/dummy/config/routes.rb +3 -0
  55. data/spec/dummy/config/secrets.yml +22 -0
  56. data/spec/dummy/config.ru +4 -0
  57. data/spec/dummy/db/schema.rb +164 -0
  58. data/spec/dummy/db/test.sqlite3 +0 -0
  59. data/spec/dummy/log/development.log +636 -0
  60. data/spec/dummy/log/test.log +6427 -0
  61. data/spec/dummy/public/404.html +67 -0
  62. data/spec/dummy/public/422.html +67 -0
  63. data/spec/dummy/public/500.html +66 -0
  64. data/spec/dummy/public/favicon.ico +0 -0
  65. data/spec/factories/attachment_factory.rb +11 -0
  66. data/spec/factories/category_factory.rb +9 -0
  67. data/spec/factories/link_category_factory.rb +6 -0
  68. data/spec/factories/page_factory.rb +11 -0
  69. data/spec/factories/post_factory.rb +19 -0
  70. data/spec/factories/post_tag_factory.rb +9 -0
  71. data/spec/factories/relationship_factory.rb +4 -0
  72. data/spec/factories/revision_factory.rb +12 -0
  73. data/spec/factories/taxonomy_factory.rb +6 -0
  74. data/spec/factories/term_factory.rb +5 -0
  75. data/spec/factories/user_factory.rb +6 -0
  76. data/spec/factories/wp_post_factory.rb +11 -0
  77. data/spec/models/wordpress/attachment_spec.rb +7 -0
  78. data/spec/models/wordpress/category_spec.rb +32 -0
  79. data/spec/models/wordpress/link_category_spec.rb +7 -0
  80. data/spec/models/wordpress/page_spec.rb +31 -0
  81. data/spec/models/wordpress/post_spec.rb +88 -0
  82. data/spec/models/wordpress/post_tag_spec.rb +21 -0
  83. data/spec/models/wordpress/relationship_spec.rb +38 -0
  84. data/spec/models/wordpress/revision_spec.rb +87 -0
  85. data/spec/models/wordpress/taxonomy_spec.rb +13 -0
  86. data/spec/models/wordpress/term_spec.rb +11 -0
  87. data/spec/models/wordpress/user_spec.rb +25 -0
  88. data/spec/models/wordpress/wp_post_spec.rb +9 -0
  89. data/spec/rails_helper.rb +15 -0
  90. data/spec/spec_helper.rb +19 -0
  91. data/spec/support/database_cleaner.rb +25 -0
  92. metadata +313 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :attachment, class: Wordpress::Attachment do
3
+ post_title 'Attachment'
4
+ post_content ""
5
+ post_excerpt ""
6
+ to_ping ""
7
+ pinged ""
8
+ post_content_filtered "'"
9
+ association :post_author
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :category, class: Wordpress::Category do
3
+ transient do
4
+ name "NAME"
5
+ end
6
+ description { "Describes #{name}" }
7
+ term_id { create(:term, name: name).id }
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :word_press_link_category, :class => 'LinkCategory' do
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :page, :class => Wordpress::Page do
3
+ post_title 'Page'
4
+ post_content "Coming Soon!"
5
+ post_excerpt ""
6
+ to_ping ""
7
+ pinged ""
8
+ post_content_filtered ""
9
+ association :post_author
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ FactoryGirl.define do
2
+ factory :post, class: Wordpress::Post do
3
+ post_title 'Test'
4
+ post_content 'CONTENT'
5
+ post_excerpt "EXCERPT"
6
+ to_ping "127.0.0.1"
7
+ pinged "127.0.0.1"
8
+ post_content_filtered "'"
9
+ association :post_author
10
+
11
+ trait :with_tags do
12
+ after(:create) do |post, evaluator|
13
+ create(:relationship, post: post, taxonomy: create(:tag, name: "Foo"))
14
+ create(:relationship, post: post, taxonomy: create(:tag, name: "Bar"))
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :tag, class: Wordpress::PostTag do
3
+ transient do
4
+ name "NAME"
5
+ end
6
+ description { "Describes #{name}" }
7
+ term_id { create(:term, name: name).id }
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ FactoryGirl.define do
2
+ factory :relationship, :class => Wordpress::Relationship do
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ FactoryGirl.define do
2
+ factory :revision, class: Wordpress::Revision do
3
+ post_title 'Revision'
4
+ post_content ""
5
+ post_excerpt ""
6
+ to_ping ""
7
+ pinged ""
8
+ post_content_filtered "'"
9
+ association :post_author
10
+ association :parent
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :taxonomy, :class => 'WpTermTaxonomy' do
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :term, class: Wordpress::Term do
3
+ name "Foobar"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :post_author, :class => Wordpress::User do
3
+ user_login "snoopy"
4
+ user_registered { Time.now }
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :wp_post, class: Wordpress::WpPost do
3
+ post_title 'Test'
4
+ post_content 'CONTENT'
5
+ post_excerpt "EXCERPT"
6
+ to_ping "127.0.0.1"
7
+ pinged "127.0.0.1"
8
+ post_content_filtered ""
9
+ association :post_author
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe Attachment, type: :model do
5
+ pending "add some examples to (or delete) #{__FILE__}"
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe Category, type: :model do
5
+ let(:category) { create(:category, name: "General") }
6
+
7
+ it "instantiates" do
8
+ expect(category.name).to eq "General"
9
+ expect(category.slug).to eq "general"
10
+ end
11
+
12
+ it "finds the category" do
13
+ category
14
+ expect(Category.find_or_create("General")).to eq category
15
+ end
16
+
17
+ it "creates the category" do
18
+ category = Category.find_or_create("Big Bang")
19
+ expect(category.slug).to eq "big-bang"
20
+ expect(category.breadcrumbs.map(&:name)).to eq ["Big Bang"]
21
+ end
22
+
23
+ it "creates a sub_category" do
24
+ parent = Category.find_or_create("Parent")
25
+ child = Category.find_or_create("Child", parent)
26
+ expect(child.parent_node).to eq parent
27
+ expect(child.parent_node.name).to eq "Parent"
28
+ expect(child.breadcrumbs.map(&:name)).to eq %w(Parent Child)
29
+ expect(parent.sub_categories).to eq [child]
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe LinkCategory, type: :model do
5
+ pending "add some examples to (or delete) #{__FILE__}"
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe Wordpress::Page, type: :model do
5
+ let(:page) { create(:page) }
6
+ let(:new_tag) { create(:tag, {name: "foo#{rand(100)}"}) }
7
+
8
+ it "sets its meta class correctly" do
9
+ expect(page).to be_kind_of Wordpress::Page
10
+ expect(page.post_type).to eq "page"
11
+ end
12
+
13
+ describe "tags association" do
14
+
15
+ it "can add a tag" do
16
+ page.tags << new_tag
17
+ expect(page.tags.count).to eq 1
18
+ expect(page.relationships.count).to eq 1
19
+ expect(page.tags.first.count).to eq 1
20
+ end
21
+
22
+ it "can add a named tag" do
23
+ page.post_tags = "foo, bar"
24
+ page.save
25
+ expect(page.tags.count).to eq 2
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,88 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe Wordpress::Post, type: :model do
5
+ let(:post) { create(:post) }
6
+ let(:new_tag) { create(:tag, {name: "foo#{rand(100)}"}) }
7
+ let(:new_category) { create(:category, name: "Foobar") }
8
+
9
+ it "sets its meta class correctly" do
10
+ expect(post).to be_kind_of Wordpress::Post
11
+ expect(post.post_type).to eq "post"
12
+ end
13
+
14
+ describe "tags association" do
15
+
16
+ it "can add a tag" do
17
+ post.tags << new_tag
18
+ expect(post.tags.count).to eq 1
19
+ expect(post.relationships.count).to eq 1
20
+ expect(post.tags.first.count).to eq 1
21
+ end
22
+
23
+ it "can add a named tag" do
24
+ post.post_tags = "foo, bar"
25
+ post.save
26
+ expect(post.tags.count).to eq 2
27
+ end
28
+
29
+ end
30
+
31
+ describe "categories" do
32
+ it "can add a category" do
33
+ post.categories << new_category
34
+ post.reload
35
+ expect(post.categories.count).to eq 1
36
+ expect(post.categories.last).to eq new_category
37
+ expect(post.categories.last).to be_kind_of Wordpress::Category
38
+ end
39
+
40
+ it "can add a named category" do
41
+ post.post_categories = new_category.name
42
+ post.save
43
+ expect(post.categories.all).to eq [new_category]
44
+ end
45
+
46
+ it "assigns by category id" do
47
+ post.assign_category_ids [new_category.id]
48
+ post.save
49
+ expect(post.categories.all).to eq [new_category]
50
+ end
51
+
52
+ it "assigns by category name" do
53
+ post.assign_category_names [new_category.name]
54
+ post.save
55
+ expect(post.categories.all).to eq [new_category]
56
+ end
57
+
58
+ it "can add category by id" do
59
+ post.post_categories = new_category.id
60
+ post.save
61
+ expect(post.categories.all).to eq [new_category]
62
+ end
63
+
64
+ it "has_category? detects on object and by name" do
65
+ post.categories << new_category
66
+ post.save
67
+ expect(post.has_category?(new_category.name)).to be true
68
+ end
69
+
70
+ it "has_category? detects on object and by category" do
71
+ post.categories << new_category
72
+ post.save
73
+ expect(post.has_category?(new_category)).to be true
74
+ end
75
+
76
+ it "revisions preserve categories" do
77
+ post.post_categories = new_category.id
78
+ post.save
79
+ expect(post.first_revision).to eq post
80
+ new_revision = post.new_revision(:post_categories => "Foo,Bar")
81
+ new_revision.save
82
+ post.reload
83
+ expect(post.post_categories).to eq "Foo,Bar"
84
+ end
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe PostTag, type: :model do
5
+ let(:tag) { create(:tag, name: "Hello Again") }
6
+
7
+ it "instantiates" do
8
+ expect(tag.name).to eq "Hello Again"
9
+ expect(tag.slug).to eq "hello-again"
10
+ end
11
+
12
+ it "finds the tag" do
13
+ tag
14
+ expect(PostTag.find_or_create("Hello Again")).to eq tag
15
+ end
16
+
17
+ it "creates the tag" do
18
+ expect(PostTag.find_or_create("Hello, Hello!").slug).to eq "hello-hello"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,38 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe Relationship, type: :model do
5
+ let(:post) { create(:post, :with_tags) }
6
+ let(:first_tag) { post.tags.first }
7
+ let(:second_tag) { post.tags[1] }
8
+
9
+ it "has tags" do
10
+ expect(post.tags.count).to eq 2
11
+ end
12
+
13
+ it "increments counts" do
14
+ expect(first_tag.count).to eq 1
15
+ expect(second_tag.count).to eq 1
16
+ end
17
+
18
+ it "decrements counts when removed from a post" do
19
+ first_tag
20
+ second_tag
21
+ post.tags.destroy_all
22
+ first_tag.reload
23
+ second_tag.reload
24
+ expect(first_tag.count).to eq 0
25
+ expect(second_tag.count).to eq 0
26
+ end
27
+
28
+ it "decrements count when post is deleted" do
29
+ first_tag
30
+ second_tag
31
+ post.destroy
32
+ first_tag.reload
33
+ second_tag.reload
34
+ expect(first_tag.count).to eq 0
35
+ expect(second_tag.count).to eq 0
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,87 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe Revision, type: :model do
5
+ let(:post) { create(:post) }
6
+ let(:revision) { post.new_revision.tap{ |r| r.save } }
7
+
8
+ it "sets its meta class correctly" do
9
+ expect(revision).to be_kind_of Wordpress::Revision
10
+ expect(revision.post_type).to eq "revision"
11
+ end
12
+
13
+ let(:params) { {} }
14
+ let(:new_revision) { post.new_revision params }
15
+ let(:new_content) { "Revised Content" }
16
+ let(:another_excerpt) { "ANOTHER EXCERPT..." }
17
+
18
+ it "should be a revision" do
19
+ expect(new_revision).to be_kind_of Wordpress::Revision
20
+ end
21
+
22
+ it "is a new record" do
23
+ expect(new_revision.new_record?).to be true
24
+ end
25
+
26
+ it "belongs to parent" do
27
+ new_revision.save
28
+ expect(post.revisions.all).to eq [new_revision]
29
+ end
30
+
31
+ describe "two revisions" do
32
+ let(:params) { { post_content: new_content } }
33
+
34
+ subject do
35
+ post.update_attributes(post_date: Date.civil(2009,1,1), post_modified: Date.civil(2010,1,1))
36
+ new_revision.save
37
+ post.new_revision({ post_excerpt: "ANOTHER" }).save
38
+ post.reload
39
+ post
40
+ end
41
+ its(:content) { should eq new_content }
42
+ its(:excerpt) { should eq "ANOTHER" }
43
+ end
44
+
45
+ describe "parameters" do
46
+ let(:params) { { post_content: new_content } }
47
+
48
+ it "should have revised content" do
49
+ expect(new_revision.post_content).to eq new_content
50
+ end
51
+
52
+ it "should not reflect in the post until saved" do
53
+ expect(post.content).to eq "CONTENT"
54
+ new_revision.save
55
+ expect(post.content).to eq new_content
56
+ end
57
+
58
+ it "should update the post_modified date" do
59
+ post.update_attributes(post_date: Date.civil(2009,1,1), post_modified: Date.civil(2010,1,1))
60
+ post.reload
61
+ expect(post.created_at.year).to eq 2009
62
+ expect(post.updated_at.year).to eq 2010
63
+ new_revision.save
64
+ expect(post.created_at.year).to eq 2009
65
+ expect(post.updated_at.year).to eq Date.today.year
66
+ end
67
+
68
+ it "defaults post_name to a revision" do
69
+ new_revision.save
70
+ expect(post.latest_revision.post_name).to eq "#{post.id}-revision-v1"
71
+ end
72
+
73
+ describe "latest_revision" do
74
+ subject do
75
+ post.update_attributes(post_date: Date.civil(2009,1,1), post_modified: Date.civil(2010,1,1))
76
+ new_revision.save
77
+ post
78
+ end
79
+
80
+ its(:title) { should eq new_revision.post_title }
81
+ its("updated_at.year") { should eq Date.today.year }
82
+ its("content") { should eq new_content }
83
+ its("created_at.year") { should eq 2009 }
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe Taxonomy, type: :model do
5
+ it "correctly determines STI class" do
6
+ expect(Taxonomy.find_sti_class("page")).to eq Wordpress::Page
7
+ end
8
+
9
+ it "correctly stores STI class name" do
10
+ expect(Wordpress::Post.sti_name).to eq "post"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails_helper'
2
+
3
+ module Wordpress
4
+ RSpec.describe Term, type: :model do
5
+ let(:term) { create(:term, name: "Hello") }
6
+ it "should create hello term" do
7
+ expect(term.name).to eq "Hello"
8
+ expect(term.slug).to eq "hello"
9
+ end
10
+ end
11
+ end