cornerstone 0.0.1 → 0.0.5

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 (177) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +23 -0
  4. data/Gemfile.lock +168 -0
  5. data/Guardfile +22 -0
  6. data/README.rdoc +4 -1
  7. data/Rakefile +11 -1
  8. data/TODO +11 -0
  9. data/VERSION +1 -0
  10. data/app/assets/images/.gitkeep +0 -0
  11. data/app/assets/javascripts/.gitkeep +0 -0
  12. data/app/assets/javascripts/cornerstone.js +11 -0
  13. data/app/assets/javascripts/cornerstone/discussions.js +2 -0
  14. data/app/assets/javascripts/cornerstone/help.js +2 -0
  15. data/app/assets/stylesheets/.gitkeep +0 -0
  16. data/app/assets/stylesheets/cornerstone.css +8 -0
  17. data/app/assets/stylesheets/cornerstone/discussions.css +4 -0
  18. data/app/assets/stylesheets/cornerstone/help.css +4 -0
  19. data/app/controllers/.gitkeep +0 -0
  20. data/app/controllers/cornerstone/admin/application_controller.rb +7 -0
  21. data/app/controllers/cornerstone/admin/articles_controller.rb +61 -0
  22. data/app/controllers/cornerstone/admin/categories_controller.rb +46 -0
  23. data/app/controllers/cornerstone/admin/discussions_controller.rb +32 -0
  24. data/app/controllers/cornerstone/application_controller.rb +6 -0
  25. data/app/controllers/cornerstone/discussions_controller.rb +58 -0
  26. data/app/controllers/cornerstone/help_controller.rb +11 -0
  27. data/app/controllers/cornerstone/posts_controller.rb +66 -0
  28. data/app/helpers/.gitkeep +0 -0
  29. data/app/helpers/cornerstone/application_helper.rb +5 -0
  30. data/app/helpers/cornerstone/discussions_helper.rb +16 -0
  31. data/app/helpers/cornerstone/help_helper.rb +4 -0
  32. data/app/mailers/cornerstone/cornerstone_mailer.rb +31 -0
  33. data/app/models/.gitkeep +0 -0
  34. data/app/models/cornerstone/article.rb +20 -0
  35. data/app/models/cornerstone/category.rb +45 -0
  36. data/app/models/cornerstone/discussion.rb +90 -0
  37. data/app/models/cornerstone/post.rb +103 -0
  38. data/app/models/cornerstone/post_observer.rb +23 -0
  39. data/app/views/.gitkeep +0 -0
  40. data/app/views/cornerstone/admin/articles/_article.html.erb +9 -0
  41. data/app/views/cornerstone/admin/articles/_form.html.erb +22 -0
  42. data/app/views/cornerstone/admin/articles/edit.html.erb +7 -0
  43. data/app/views/cornerstone/admin/articles/index.html.erb +25 -0
  44. data/app/views/cornerstone/admin/articles/new.html.erb +6 -0
  45. data/app/views/cornerstone/admin/articles/show.html.erb +4 -0
  46. data/app/views/cornerstone/admin/categories/_category.html.erb +12 -0
  47. data/app/views/cornerstone/admin/categories/_form.html.erb +17 -0
  48. data/app/views/cornerstone/admin/categories/edit.html.erb +6 -0
  49. data/app/views/cornerstone/admin/categories/index.html.erb +11 -0
  50. data/app/views/cornerstone/admin/categories/new.html.erb +6 -0
  51. data/app/views/cornerstone/admin/discussions/edit.html.erb +7 -0
  52. data/app/views/cornerstone/cornerstone_mailer/new_discussion.html.erb +14 -0
  53. data/app/views/cornerstone/cornerstone_mailer/new_discussion.text.erb +5 -0
  54. data/app/views/cornerstone/cornerstone_mailer/new_discussion_user.html.erb +7 -0
  55. data/app/views/cornerstone/cornerstone_mailer/new_post.html.erb +7 -0
  56. data/app/views/cornerstone/cornerstone_mailer/new_post.text.erb +8 -0
  57. data/app/views/cornerstone/discussions/_discussion.html.erb +12 -0
  58. data/app/views/cornerstone/discussions/_discussion_category.html.erb +14 -0
  59. data/app/views/cornerstone/discussions/_form.html.erb +33 -0
  60. data/app/views/cornerstone/discussions/_latest_discussion.html.erb +4 -0
  61. data/app/views/cornerstone/discussions/categorical_index.html.erb +27 -0
  62. data/app/views/cornerstone/discussions/index.html.erb +25 -0
  63. data/app/views/cornerstone/discussions/new.html.erb +6 -0
  64. data/app/views/cornerstone/discussions/show.html.erb +19 -0
  65. data/app/views/cornerstone/help/index.html.erb +7 -0
  66. data/app/views/cornerstone/posts/_fields.html.erb +44 -0
  67. data/app/views/cornerstone/posts/_form.html.erb +19 -0
  68. data/app/views/cornerstone/posts/_post.html.erb +17 -0
  69. data/app/views/cornerstone/posts/edit.html.erb +9 -0
  70. data/app/views/cornerstone/shared/_errors.html.erb +11 -0
  71. data/app/views/cornerstone/shared/_flash_messages.html.erb +15 -0
  72. data/app/views/layouts/cornerstone/application.html.erb +16 -0
  73. data/config/cucumber.yml +8 -0
  74. data/config/locales/cornerstone.action_mailer.en.yml +9 -0
  75. data/config/routes.rb +24 -0
  76. data/cornerstone-0.0.1.gem +0 -0
  77. data/cornerstone.gemspec +33 -0
  78. data/db/migrate/20110723004024_create_cornerstone_discussions.rb +17 -0
  79. data/db/migrate/20110804190853_create_cornerstone_categories.rb +15 -0
  80. data/db/migrate/20110809233551_create_cornerstone_posts.rb +13 -0
  81. data/db/migrate/20111006172857_create_cornerstone_articles.rb +12 -0
  82. data/lib/cornerstone.rb +6 -0
  83. data/lib/cornerstone/acts_as_cornerstone_user.rb +79 -0
  84. data/lib/cornerstone/config.rb +33 -0
  85. data/lib/cornerstone/controller_additions.rb +25 -0
  86. data/lib/cornerstone/engine.rb +8 -1
  87. data/lib/cornerstone/exceptions.rb +16 -0
  88. data/lib/cornerstone/helpers.rb +35 -0
  89. data/lib/tasks/cucumber.rake +65 -0
  90. data/lib/templates/cornerstone_config.rb +31 -0
  91. data/script/cucumber +10 -0
  92. data/script/rails +7 -0
  93. data/spec/controllers/cornerstone/admin/articles_controller_spec.rb +250 -0
  94. data/spec/controllers/cornerstone/admin/categories_controller_spec.rb +205 -0
  95. data/spec/controllers/cornerstone/admin/discussions_controller_spec.rb +95 -0
  96. data/spec/controllers/cornerstone/application_controller_spec.rb +34 -0
  97. data/spec/controllers/cornerstone/discussions_controller_spec.rb +157 -0
  98. data/spec/controllers/cornerstone/help_controller_spec.rb +20 -0
  99. data/spec/controllers/cornerstone/posts_controller_spec.rb +212 -0
  100. data/spec/dummy/Rakefile +7 -0
  101. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  102. data/spec/dummy/app/assets/javascripts/tester.js +2 -0
  103. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  104. data/spec/dummy/app/assets/stylesheets/tester.css +4 -0
  105. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  106. data/spec/dummy/app/controllers/tester_controller.rb +7 -0
  107. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  108. data/spec/dummy/app/helpers/tester_helper.rb +6 -0
  109. data/spec/dummy/app/mailers/.gitkeep +0 -0
  110. data/spec/dummy/app/models/.gitkeep +0 -0
  111. data/spec/dummy/app/models/user.rb +23 -0
  112. data/spec/dummy/app/views/devise/confirmations/new.html.erb +12 -0
  113. data/spec/dummy/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  114. data/spec/dummy/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  115. data/spec/dummy/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  116. data/spec/dummy/app/views/devise/passwords/edit.html.erb +16 -0
  117. data/spec/dummy/app/views/devise/passwords/new.html.erb +12 -0
  118. data/spec/dummy/app/views/devise/registrations/edit.html.erb +29 -0
  119. data/spec/dummy/app/views/devise/registrations/new.html.erb +22 -0
  120. data/spec/dummy/app/views/devise/sessions/new.html.erb +19 -0
  121. data/spec/dummy/app/views/devise/shared/_links.erb +25 -0
  122. data/spec/dummy/app/views/devise/unlocks/new.html.erb +12 -0
  123. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  124. data/spec/dummy/app/views/tester/index.html.erb +14 -0
  125. data/spec/dummy/config.ru +4 -0
  126. data/spec/dummy/config/application.rb +42 -0
  127. data/spec/dummy/config/boot.rb +10 -0
  128. data/spec/dummy/config/database.yml +28 -0
  129. data/spec/dummy/config/environment.rb +5 -0
  130. data/spec/dummy/config/environments/development.rb +31 -0
  131. data/spec/dummy/config/environments/production.rb +54 -0
  132. data/spec/dummy/config/environments/test.rb +39 -0
  133. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  134. data/spec/dummy/config/initializers/cornerstone_config.rb +30 -0
  135. data/spec/dummy/config/initializers/devise.rb +204 -0
  136. data/spec/dummy/config/initializers/inflections.rb +10 -0
  137. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  138. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  139. data/spec/dummy/config/initializers/session_store.rb +8 -0
  140. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  141. data/spec/dummy/config/locales/devise.en.yml +53 -0
  142. data/spec/dummy/config/locales/en.yml +5 -0
  143. data/spec/dummy/config/routes.rb +65 -0
  144. data/spec/dummy/db/migrate/20110724011421_create_user.rb +11 -0
  145. data/spec/dummy/db/migrate/20110724194307_devise_create_users.rb +41 -0
  146. data/spec/dummy/db/migrate/20110804174004_add_name_to_user.rb +5 -0
  147. data/spec/dummy/db/schema.rb +76 -0
  148. data/spec/dummy/log/.gitkeep +0 -0
  149. data/spec/dummy/public/404.html +26 -0
  150. data/spec/dummy/public/422.html +26 -0
  151. data/spec/dummy/public/500.html +26 -0
  152. data/spec/dummy/public/favicon.ico +0 -0
  153. data/spec/dummy/script/rails +6 -0
  154. data/spec/dummy/test/functional/tester_controller_test.rb +9 -0
  155. data/spec/dummy/test/unit/helpers/tester_helper_test.rb +4 -0
  156. data/spec/fixtures/cornerstone/cornerstone_mailer/new_discussion +3 -0
  157. data/spec/lib/cornerstone/acts_as_cornerstone_user_spec.rb +56 -0
  158. data/spec/lib/cornerstone/helpers_spec.rb +32 -0
  159. data/spec/mailers/cornerstone/cornerstone_mailer_spec.rb +55 -0
  160. data/spec/models/cornerstone/article_spec.rb +25 -0
  161. data/spec/models/cornerstone/category_spec.rb +97 -0
  162. data/spec/models/cornerstone/discussion_spec.rb +243 -0
  163. data/spec/models/cornerstone/post_observer_spec.rb +65 -0
  164. data/spec/models/cornerstone/post_spec.rb +210 -0
  165. data/spec/requests/emails_spec.rb +51 -0
  166. data/spec/requests/interact_discussions_spec.rb +103 -0
  167. data/spec/requests/manage_articles_spec.rb +59 -0
  168. data/spec/requests/manage_categories_spec.rb +64 -0
  169. data/spec/requests/view_home_spec.rb +26 -0
  170. data/spec/spec_helper.rb +40 -0
  171. data/spec/support/devise.rb +4 -0
  172. data/spec/support/factories.rb +62 -0
  173. data/spec/support/general_helper_methods.rb +20 -0
  174. data/spec/support/mailer_macros.rb +15 -0
  175. data/spec/support/mass_assignment.rb +46 -0
  176. data/tmp/log/development.log +0 -0
  177. metadata +301 -20
@@ -0,0 +1,11 @@
1
+ class CreateUser < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+ t.string :email
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,41 @@
1
+ class DeviseCreateUsers < ActiveRecord::Migration
2
+
3
+ # lets drop the current user table and use devise
4
+ drop_table :users
5
+
6
+ def self.up
7
+ create_table(:users) do |t|
8
+ t.database_authenticatable :null => false
9
+ t.recoverable
10
+ t.rememberable
11
+ t.trackable
12
+
13
+ # t.encryptable
14
+ # t.confirmable
15
+ # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
16
+ # t.token_authenticatable
17
+
18
+
19
+ t.timestamps
20
+ end
21
+
22
+ add_index :users, :email, :unique => true
23
+ add_index :users, :reset_password_token, :unique => true
24
+ # add_index :users, :confirmation_token, :unique => true
25
+ # add_index :users, :unlock_token, :unique => true
26
+ # add_index :users, :authentication_token, :unique => true
27
+ end
28
+
29
+ def self.down
30
+ drop_table :users
31
+
32
+ # old table
33
+ create_table :users do |t|
34
+ t.string :name
35
+ t.string :email
36
+
37
+ t.timestamps
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,5 @@
1
+ class AddNameToUser < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :name, :string
4
+ end
5
+ end
@@ -0,0 +1,76 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 20111006172857) do
14
+
15
+ create_table "cornerstone_articles", :force => true do |t|
16
+ t.string "title"
17
+ t.text "body"
18
+ t.integer "category_id"
19
+ t.datetime "created_at"
20
+ t.datetime "updated_at"
21
+ end
22
+
23
+ create_table "cornerstone_categories", :force => true do |t|
24
+ t.string "name"
25
+ t.string "category_type"
26
+ t.text "description"
27
+ t.integer "item_count", :default => 0
28
+ t.string "latest_discussion_author"
29
+ t.datetime "latest_discussion_date"
30
+ t.datetime "created_at"
31
+ t.datetime "updated_at"
32
+ end
33
+
34
+ create_table "cornerstone_discussions", :force => true do |t|
35
+ t.integer "user_id"
36
+ t.integer "category_id"
37
+ t.string "subject"
38
+ t.string "status", :default => "Open"
39
+ t.boolean "privte", :default => false
40
+ t.integer "reply_count", :default => 0
41
+ t.string "latest_post_author"
42
+ t.datetime "latest_post_date"
43
+ t.datetime "created_at"
44
+ t.datetime "updated_at"
45
+ end
46
+
47
+ create_table "cornerstone_posts", :force => true do |t|
48
+ t.integer "discussion_id"
49
+ t.integer "user_id"
50
+ t.string "name"
51
+ t.string "email"
52
+ t.text "body"
53
+ t.datetime "created_at"
54
+ t.datetime "updated_at"
55
+ end
56
+
57
+ create_table "users", :force => true do |t|
58
+ t.string "email", :default => "", :null => false
59
+ t.string "encrypted_password", :limit => 128, :default => "", :null => false
60
+ t.string "reset_password_token"
61
+ t.datetime "reset_password_sent_at"
62
+ t.datetime "remember_created_at"
63
+ t.integer "sign_in_count", :default => 0
64
+ t.datetime "current_sign_in_at"
65
+ t.datetime "last_sign_in_at"
66
+ t.string "current_sign_in_ip"
67
+ t.string "last_sign_in_ip"
68
+ t.datetime "created_at"
69
+ t.datetime "updated_at"
70
+ t.string "name"
71
+ end
72
+
73
+ add_index "users", ["email"], :name => "index_users_on_email", :unique => true
74
+ add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
75
+
76
+ end
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class TesterControllerTest < ActionController::TestCase
4
+ test "should get index" do
5
+ get :index
6
+ assert_response :success
7
+ end
8
+
9
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class TesterHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,3 @@
1
+ CornerstoneMailer#new_discussion
2
+
3
+ Hi, find me in app/views/cornerstone/cornerstone_mailer/new_discussion
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cornerstone::ActsAsCornerstoneUser do
4
+
5
+ # class TestUser < ActiveRecord::Base
6
+ # include Cornerstone::ActsAsCornerstoneUser
7
+ # end
8
+
9
+ # class TestUserTwo < ActiveRecord::Base
10
+ # include Cornerstone::ActsAsCornerstoneUser
11
+ # end
12
+
13
+ # context "associations:" do
14
+ # before do
15
+ # TestUser.send(:acts_as_cornerstone_user)
16
+ # end
17
+
18
+ # context "for Cornerstone::Discussion" do
19
+ # it "a Cornerstone Discussion should be related to the given model (User)" do
20
+ # TestUser.reflect_on_association(:cornerstone_discussions).should_not be_nil
21
+ # end
22
+ # end
23
+
24
+ # it "a Cornerstone Post should be related to the given model (User)" do
25
+ # TestUser.reflect_on_association(:cornerstone_posts).should_not be_nil
26
+ # end
27
+
28
+ # context "belongs_to relationships" do
29
+ # it "sets up the relationship for a Discussion" do
30
+ # Cornerstone::Discussion.reflect_on_association(:user).should_not be_nil
31
+ # end
32
+
33
+ # it "sets up the relationship for a Post" do
34
+ # Cornerstone::Post.reflect_on_association(:user).should_not be_nil
35
+ # end
36
+ # end
37
+ # end
38
+
39
+ context "options:" do
40
+ pending "sets some default options"
41
+ pending "sets the auth_with option"
42
+ pending "sets the user_name option"
43
+ pending "user_name must not be nil"
44
+ pending "sets the user_email option"
45
+ pending "User_email must not be nil"
46
+
47
+ end
48
+
49
+ context "Instance Methods" do
50
+ pending "#cornerstone_name"
51
+ pending "#cornerstone_email"
52
+ pending "#cornerstone_admin?"
53
+ end
54
+
55
+
56
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cornerstone::Helpers do
4
+ include Warden::Test::Helpers
5
+
6
+ class TestController < Cornerstone::ApplicationController
7
+ include Cornerstone::Helpers
8
+ end
9
+
10
+ describe "#current_cornerstone_user" do
11
+
12
+ context "using warden" do
13
+ pending "should return the current signed in user"
14
+ end
15
+
16
+ context "using a Proc" do
17
+ pending "should return the current signed in user"
18
+ end
19
+
20
+ end
21
+ describe "#cornerstone_admin?" do
22
+ context "no current user" do
23
+ pending "should return false"
24
+ end
25
+ context "with a current user" do
26
+ pending "should return false if the user is not an admin"
27
+ pending "should return false if the user is an admin"
28
+ end
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe Cornerstone::CornerstoneMailer do
4
+ describe "new_discussion" do
5
+ let(:discussion) { Factory(:discussion_w_user) }
6
+ let(:mail) { Cornerstone::CornerstoneMailer.new_discussion(discussion.posts.first, discussion) }
7
+
8
+ it "renders the headers" do
9
+ mail.subject.should eq(I18n.t('cornerstone.cornerstone_mailer.new_discussion.subject'))
10
+ mail.to.should eq(Cornerstone::Config.admin_emails)
11
+ mail.from.should eq([Cornerstone::Config.mailer_from])
12
+ end
13
+
14
+ it "renders the body" do
15
+ mail.body.encoded.should match("new discussion")
16
+ end
17
+ end
18
+
19
+ describe "new_discussion_user" do
20
+ let(:discussion) { Factory(:discussion_w_user) }
21
+ let(:mail) { Cornerstone::CornerstoneMailer.new_discussion_user(discussion.posts.first, discussion) }
22
+
23
+ it "renders the headers" do
24
+ mail.subject.should eq(I18n.t('cornerstone.cornerstone_mailer.new_discussion_user.subject'))
25
+ mail.to.should eq([discussion.posts.first.author_email])
26
+ mail.from.should eq([Cornerstone::Config.mailer_from])
27
+ end
28
+
29
+ it "renders the body" do
30
+ mail.body.encoded.should match("Your discussion")
31
+ end
32
+ end
33
+
34
+ describe "new_post" do
35
+ let(:discussion) { Factory(:discussion_w_user) }
36
+ let(:post) { discussion.posts.first }
37
+ let(:mail) { Cornerstone::CornerstoneMailer.new_post(post.author_name,
38
+ post.author_email, post, discussion) }
39
+
40
+ it "renders the headers" do
41
+ mailto = [post.author_email]
42
+
43
+ subject = "Cornerstone: New reply for - #{discussion.subject}"
44
+ mail.subject.should eq(subject)
45
+ mail.to.should eq(mailto)
46
+ mail.from.should eq([Cornerstone::Config.mailer_from])
47
+ end
48
+
49
+ it "renders the body" do
50
+ mail.body.encoded.should match("new reply")
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cornerstone::Article do
4
+ before do
5
+ @article = Factory.build(:article)
6
+ end
7
+ # == CONSTANTS == #
8
+ # == ASSOCIATIONS == #
9
+ # == ACCESSIBILITY == #
10
+ # == SCOPES == #
11
+
12
+ # == VALIDATIONS == #
13
+ [:title, :body, :category].each do |attr|
14
+ it "requires a #{attr}" do
15
+ @article.send("#{attr}=", nil)
16
+ @article.should have(1).error_on(attr)
17
+ end
18
+ end
19
+
20
+ # == CALLBACKS == #
21
+ # == CLASS METHODS == #
22
+ # == INSTANCE METHODS == #
23
+
24
+ end
25
+
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cornerstone::Category do
4
+
5
+ # == ACCESSIBILITY == #
6
+ context "Accessibility:" do
7
+ before do
8
+ @category = Factory(:category)
9
+ end
10
+ {:item_count => 5}.each do |attr, value|
11
+ it "should not let me assign the ##{attr}" do
12
+ @category.should_not allow_mass_assignment_of(attr => value)
13
+ end
14
+ end
15
+ end
16
+
17
+ # == SCOPES == #
18
+ context "Scopes:" do
19
+ describe "#discussions" do
20
+ it "returns categories with category_type = Discussion" do
21
+ @category = Factory(:category, :category_type => "Discussion")
22
+ Factory(:category, :category_type => "Article")
23
+ test = Cornerstone::Category.discussions
24
+ test.size.should == 1
25
+ test.should == [@category]
26
+ end
27
+ end
28
+ describe "#articles" do
29
+ it "returns categories with category_type = Article" do
30
+ @category = Factory(:category, :category_type => "Article")
31
+ Factory(:category, :category_type => "Discussion")
32
+ test = Cornerstone::Category.articles
33
+ test.size.should == 1
34
+ test.should == [@category]
35
+ end
36
+ end
37
+ end
38
+
39
+ # == VALIDATIONS == #
40
+
41
+
42
+ context "Validations:" do
43
+ before do
44
+ @category = Factory(:category)
45
+ end
46
+
47
+ [:name, :category_type, :description].each do |attr|
48
+ it "requires a #{attr}" do
49
+ @category.send("#{attr}=", nil)
50
+ @category.should have(1).error_on(attr)
51
+ end
52
+ end
53
+
54
+ {:name => 50,
55
+ :description => 500}.each do |attr, size|
56
+ it "##{attr} should be #{size} characters or less" do
57
+ @category.send("#{attr}=", random_alphanumeric(size + 1))
58
+ @category.should have(1).error_on(attr)
59
+ end
60
+ end
61
+
62
+ it "should only include the hard coded category types" do
63
+ @category.category_type = "wiggles"
64
+ @category.should have(1).error_on(:category_type)
65
+ end
66
+
67
+ end
68
+
69
+
70
+ # == CALLBACKS == #
71
+
72
+ # == CLASS METHODS == #
73
+
74
+ # == INSTANCE METHODS == #
75
+ context "Instance Methods:" do
76
+ before do
77
+ @category = Factory(:category)
78
+ end
79
+
80
+ describe "#latest_discussions" do
81
+ it "calls the latest_discussion scope with the given number of results required" do
82
+ Cornerstone::Discussion.should_receive(:latest_for_category).with(@category, 5)
83
+ @category.latest_discussions(5)
84
+ end
85
+ end
86
+
87
+ describe "#latest_discussion" do
88
+ it "returns the latest discussion" do
89
+ d = Factory(:discussion, :category => @category)
90
+ @category.latest_discussion.should == d
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+