cornerstone 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +168 -0
- data/Guardfile +22 -0
- data/README.rdoc +4 -1
- data/Rakefile +11 -1
- data/TODO +11 -0
- data/VERSION +1 -0
- data/app/assets/images/.gitkeep +0 -0
- data/app/assets/javascripts/.gitkeep +0 -0
- data/app/assets/javascripts/cornerstone.js +11 -0
- data/app/assets/javascripts/cornerstone/discussions.js +2 -0
- data/app/assets/javascripts/cornerstone/help.js +2 -0
- data/app/assets/stylesheets/.gitkeep +0 -0
- data/app/assets/stylesheets/cornerstone.css +8 -0
- data/app/assets/stylesheets/cornerstone/discussions.css +4 -0
- data/app/assets/stylesheets/cornerstone/help.css +4 -0
- data/app/controllers/.gitkeep +0 -0
- data/app/controllers/cornerstone/admin/application_controller.rb +7 -0
- data/app/controllers/cornerstone/admin/articles_controller.rb +61 -0
- data/app/controllers/cornerstone/admin/categories_controller.rb +46 -0
- data/app/controllers/cornerstone/admin/discussions_controller.rb +32 -0
- data/app/controllers/cornerstone/application_controller.rb +6 -0
- data/app/controllers/cornerstone/discussions_controller.rb +58 -0
- data/app/controllers/cornerstone/help_controller.rb +11 -0
- data/app/controllers/cornerstone/posts_controller.rb +66 -0
- data/app/helpers/.gitkeep +0 -0
- data/app/helpers/cornerstone/application_helper.rb +5 -0
- data/app/helpers/cornerstone/discussions_helper.rb +16 -0
- data/app/helpers/cornerstone/help_helper.rb +4 -0
- data/app/mailers/cornerstone/cornerstone_mailer.rb +31 -0
- data/app/models/.gitkeep +0 -0
- data/app/models/cornerstone/article.rb +20 -0
- data/app/models/cornerstone/category.rb +45 -0
- data/app/models/cornerstone/discussion.rb +90 -0
- data/app/models/cornerstone/post.rb +103 -0
- data/app/models/cornerstone/post_observer.rb +23 -0
- data/app/views/.gitkeep +0 -0
- data/app/views/cornerstone/admin/articles/_article.html.erb +9 -0
- data/app/views/cornerstone/admin/articles/_form.html.erb +22 -0
- data/app/views/cornerstone/admin/articles/edit.html.erb +7 -0
- data/app/views/cornerstone/admin/articles/index.html.erb +25 -0
- data/app/views/cornerstone/admin/articles/new.html.erb +6 -0
- data/app/views/cornerstone/admin/articles/show.html.erb +4 -0
- data/app/views/cornerstone/admin/categories/_category.html.erb +12 -0
- data/app/views/cornerstone/admin/categories/_form.html.erb +17 -0
- data/app/views/cornerstone/admin/categories/edit.html.erb +6 -0
- data/app/views/cornerstone/admin/categories/index.html.erb +11 -0
- data/app/views/cornerstone/admin/categories/new.html.erb +6 -0
- data/app/views/cornerstone/admin/discussions/edit.html.erb +7 -0
- data/app/views/cornerstone/cornerstone_mailer/new_discussion.html.erb +14 -0
- data/app/views/cornerstone/cornerstone_mailer/new_discussion.text.erb +5 -0
- data/app/views/cornerstone/cornerstone_mailer/new_discussion_user.html.erb +7 -0
- data/app/views/cornerstone/cornerstone_mailer/new_post.html.erb +7 -0
- data/app/views/cornerstone/cornerstone_mailer/new_post.text.erb +8 -0
- data/app/views/cornerstone/discussions/_discussion.html.erb +12 -0
- data/app/views/cornerstone/discussions/_discussion_category.html.erb +14 -0
- data/app/views/cornerstone/discussions/_form.html.erb +33 -0
- data/app/views/cornerstone/discussions/_latest_discussion.html.erb +4 -0
- data/app/views/cornerstone/discussions/categorical_index.html.erb +27 -0
- data/app/views/cornerstone/discussions/index.html.erb +25 -0
- data/app/views/cornerstone/discussions/new.html.erb +6 -0
- data/app/views/cornerstone/discussions/show.html.erb +19 -0
- data/app/views/cornerstone/help/index.html.erb +7 -0
- data/app/views/cornerstone/posts/_fields.html.erb +44 -0
- data/app/views/cornerstone/posts/_form.html.erb +19 -0
- data/app/views/cornerstone/posts/_post.html.erb +17 -0
- data/app/views/cornerstone/posts/edit.html.erb +9 -0
- data/app/views/cornerstone/shared/_errors.html.erb +11 -0
- data/app/views/cornerstone/shared/_flash_messages.html.erb +15 -0
- data/app/views/layouts/cornerstone/application.html.erb +16 -0
- data/config/cucumber.yml +8 -0
- data/config/locales/cornerstone.action_mailer.en.yml +9 -0
- data/config/routes.rb +24 -0
- data/cornerstone-0.0.1.gem +0 -0
- data/cornerstone.gemspec +33 -0
- data/db/migrate/20110723004024_create_cornerstone_discussions.rb +17 -0
- data/db/migrate/20110804190853_create_cornerstone_categories.rb +15 -0
- data/db/migrate/20110809233551_create_cornerstone_posts.rb +13 -0
- data/db/migrate/20111006172857_create_cornerstone_articles.rb +12 -0
- data/lib/cornerstone.rb +6 -0
- data/lib/cornerstone/acts_as_cornerstone_user.rb +79 -0
- data/lib/cornerstone/config.rb +33 -0
- data/lib/cornerstone/controller_additions.rb +25 -0
- data/lib/cornerstone/engine.rb +8 -1
- data/lib/cornerstone/exceptions.rb +16 -0
- data/lib/cornerstone/helpers.rb +35 -0
- data/lib/tasks/cucumber.rake +65 -0
- data/lib/templates/cornerstone_config.rb +31 -0
- data/script/cucumber +10 -0
- data/script/rails +7 -0
- data/spec/controllers/cornerstone/admin/articles_controller_spec.rb +250 -0
- data/spec/controllers/cornerstone/admin/categories_controller_spec.rb +205 -0
- data/spec/controllers/cornerstone/admin/discussions_controller_spec.rb +95 -0
- data/spec/controllers/cornerstone/application_controller_spec.rb +34 -0
- data/spec/controllers/cornerstone/discussions_controller_spec.rb +157 -0
- data/spec/controllers/cornerstone/help_controller_spec.rb +20 -0
- data/spec/controllers/cornerstone/posts_controller_spec.rb +212 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/javascripts/tester.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/assets/stylesheets/tester.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/tester_controller.rb +7 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/tester_helper.rb +6 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/user.rb +23 -0
- data/spec/dummy/app/views/devise/confirmations/new.html.erb +12 -0
- data/spec/dummy/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/spec/dummy/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/spec/dummy/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/spec/dummy/app/views/devise/passwords/edit.html.erb +16 -0
- data/spec/dummy/app/views/devise/passwords/new.html.erb +12 -0
- data/spec/dummy/app/views/devise/registrations/edit.html.erb +29 -0
- data/spec/dummy/app/views/devise/registrations/new.html.erb +22 -0
- data/spec/dummy/app/views/devise/sessions/new.html.erb +19 -0
- data/spec/dummy/app/views/devise/shared/_links.erb +25 -0
- data/spec/dummy/app/views/devise/unlocks/new.html.erb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/tester/index.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +42 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +28 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +31 -0
- data/spec/dummy/config/environments/production.rb +54 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cornerstone_config.rb +30 -0
- data/spec/dummy/config/initializers/devise.rb +204 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/devise.en.yml +53 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +65 -0
- data/spec/dummy/db/migrate/20110724011421_create_user.rb +11 -0
- data/spec/dummy/db/migrate/20110724194307_devise_create_users.rb +41 -0
- data/spec/dummy/db/migrate/20110804174004_add_name_to_user.rb +5 -0
- data/spec/dummy/db/schema.rb +76 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/functional/tester_controller_test.rb +9 -0
- data/spec/dummy/test/unit/helpers/tester_helper_test.rb +4 -0
- data/spec/fixtures/cornerstone/cornerstone_mailer/new_discussion +3 -0
- data/spec/lib/cornerstone/acts_as_cornerstone_user_spec.rb +56 -0
- data/spec/lib/cornerstone/helpers_spec.rb +32 -0
- data/spec/mailers/cornerstone/cornerstone_mailer_spec.rb +55 -0
- data/spec/models/cornerstone/article_spec.rb +25 -0
- data/spec/models/cornerstone/category_spec.rb +97 -0
- data/spec/models/cornerstone/discussion_spec.rb +243 -0
- data/spec/models/cornerstone/post_observer_spec.rb +65 -0
- data/spec/models/cornerstone/post_spec.rb +210 -0
- data/spec/requests/emails_spec.rb +51 -0
- data/spec/requests/interact_discussions_spec.rb +103 -0
- data/spec/requests/manage_articles_spec.rb +59 -0
- data/spec/requests/manage_categories_spec.rb +64 -0
- data/spec/requests/view_home_spec.rb +26 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/support/devise.rb +4 -0
- data/spec/support/factories.rb +62 -0
- data/spec/support/general_helper_methods.rb +20 -0
- data/spec/support/mailer_macros.rb +15 -0
- data/spec/support/mass_assignment.rb +46 -0
- data/tmp/log/development.log +0 -0
- metadata +301 -20
@@ -0,0 +1,65 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
+
# files.
|
6
|
+
|
7
|
+
|
8
|
+
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
|
9
|
+
|
10
|
+
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
|
11
|
+
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'cucumber/rake/task'
|
15
|
+
|
16
|
+
namespace :cucumber do
|
17
|
+
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
|
18
|
+
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
|
19
|
+
t.fork = true # You may get faster startup if you set this to false
|
20
|
+
t.profile = 'default'
|
21
|
+
end
|
22
|
+
|
23
|
+
Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
|
24
|
+
t.binary = vendored_cucumber_bin
|
25
|
+
t.fork = true # You may get faster startup if you set this to false
|
26
|
+
t.profile = 'wip'
|
27
|
+
end
|
28
|
+
|
29
|
+
Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
|
30
|
+
t.binary = vendored_cucumber_bin
|
31
|
+
t.fork = true # You may get faster startup if you set this to false
|
32
|
+
t.profile = 'rerun'
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Run all features'
|
36
|
+
task :all => [:ok, :wip]
|
37
|
+
|
38
|
+
task :statsetup do
|
39
|
+
require 'rails/code_statistics'
|
40
|
+
::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
|
41
|
+
::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
desc 'Alias for cucumber:ok'
|
45
|
+
task :cucumber => 'cucumber:ok'
|
46
|
+
|
47
|
+
task :default => :cucumber
|
48
|
+
|
49
|
+
task :features => :cucumber do
|
50
|
+
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
|
51
|
+
end
|
52
|
+
|
53
|
+
# In case we don't have ActiveRecord, append a no-op task that we can depend upon.
|
54
|
+
task 'db:test:prepare' do
|
55
|
+
end
|
56
|
+
|
57
|
+
task :stats => 'cucumber:statsetup'
|
58
|
+
rescue LoadError
|
59
|
+
desc 'cucumber rake task not available (cucumber not installed)'
|
60
|
+
task :cucumber do
|
61
|
+
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Use this hook to configure cornerstone.
|
2
|
+
Cornerstone::Config.setup do |config|
|
3
|
+
|
4
|
+
# == Authenticated User Method
|
5
|
+
# Specify the method in which your application accesses the authenticated user.
|
6
|
+
# You may use a Proc to call a helper method in your application. The helper method
|
7
|
+
# must return an authenticated user.
|
8
|
+
# Alternatively, you may specify ':warden' if you are using Warden for authentication.
|
9
|
+
#
|
10
|
+
# Examples:
|
11
|
+
#
|
12
|
+
# config.auth_with = Proc.new {|helper| helper.current_user}
|
13
|
+
# config.auth_with = :warden
|
14
|
+
config.auth_with = :warden
|
15
|
+
|
16
|
+
|
17
|
+
# == Discussion Statuses
|
18
|
+
# An array of strings which specify the status options for a discussion.
|
19
|
+
# The first status option becomes the default value used in the database.
|
20
|
+
# The last status option becomes the default value when a discussion is 'closed.'
|
21
|
+
config.discussion_statuses = ["Open", "Resolved"]
|
22
|
+
|
23
|
+
# == Mailer From Address
|
24
|
+
# The default 'from' email address for the mailer to use.
|
25
|
+
config.mailer_from = "no-reply@cornerstone.com"
|
26
|
+
|
27
|
+
# == Administrators emails
|
28
|
+
# An array of strings which specify which users to email when a new discussion is created.
|
29
|
+
config.admin_emails = ["support@cornerstone.com"]
|
30
|
+
|
31
|
+
end
|
data/script/cucumber
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
|
4
|
+
if vendored_cucumber_bin
|
5
|
+
load File.expand_path(vendored_cucumber_bin)
|
6
|
+
else
|
7
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
8
|
+
require 'cucumber'
|
9
|
+
load Cucumber::BINARY
|
10
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_PATH = File.expand_path('../..', __FILE__)
|
6
|
+
load File.expand_path('../../spec/dummy/script/rails', __FILE__)
|
7
|
+
|
@@ -0,0 +1,250 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cornerstone::Admin::ArticlesController do
|
4
|
+
|
5
|
+
def mock_category(stubs={})
|
6
|
+
@mock_category ||= mock_model(Cornerstone::Category, stubs).as_null_object
|
7
|
+
end
|
8
|
+
|
9
|
+
def mock_article(stubs={})
|
10
|
+
@mock_article ||= mock_model(Cornerstone::Article, stubs).as_null_object
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "GET index" do
|
14
|
+
context "with an administrator" do
|
15
|
+
before do
|
16
|
+
sign_in_admin
|
17
|
+
end
|
18
|
+
it "should expose articles as @articles" do
|
19
|
+
Cornerstone::Article.should_receive(:all) {[mock_article]}
|
20
|
+
get :index, :use_route => :cornerstone
|
21
|
+
assigns[:articles].should eql([mock_article])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context "with a normal user" do
|
25
|
+
it "raises the unauthorized error" do
|
26
|
+
lambda {
|
27
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
28
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "GET show" do
|
34
|
+
context "with an administrator" do
|
35
|
+
before do
|
36
|
+
sign_in_admin
|
37
|
+
end
|
38
|
+
it "should expose the requested article as @article" do
|
39
|
+
Cornerstone::Article.should_receive(:find).with("37") {mock_article}
|
40
|
+
get :show, :id => "37", :use_route => :cornerstone
|
41
|
+
assigns[:article].should eql(mock_article)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context "with a normal user" do
|
45
|
+
it "raises the unauthorized error" do
|
46
|
+
lambda {
|
47
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
48
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "GET new" do
|
54
|
+
context "with an administrator" do
|
55
|
+
before do
|
56
|
+
sign_in_admin
|
57
|
+
end
|
58
|
+
it "should expose a new article as @article" do
|
59
|
+
Cornerstone::Article.should_receive(:new) {mock_article}
|
60
|
+
get :new, :use_route => :cornerstone
|
61
|
+
assigns[:article].should equal(mock_article)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "exposes article categories for selection as @categories" do
|
65
|
+
Cornerstone::Category.should_receive(:articles) {mock_category}
|
66
|
+
get :new, :use_route => :cornerstone
|
67
|
+
assigns(:categories).should equal(mock_category)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "with a normal user" do
|
71
|
+
it "raises the unauthorized error" do
|
72
|
+
lambda {
|
73
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
74
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "POST create" do
|
80
|
+
context "with an administrator" do
|
81
|
+
before do
|
82
|
+
sign_in_admin
|
83
|
+
end
|
84
|
+
context "with valid parameters" do
|
85
|
+
it "exposes a newly created article as @article" do
|
86
|
+
Cornerstone::Article.should_receive(:new)
|
87
|
+
.with({'these' => 'params'}) {mock_article :save => true}
|
88
|
+
post :create, :article => {:these => 'params'}, :use_route => :cornerstone
|
89
|
+
assigns(:article).should equal(mock_article)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "redirects to the article" do
|
93
|
+
Cornerstone::Article.stub!(:new) {mock_article(:save => true,
|
94
|
+
:category => mock_category)}
|
95
|
+
post :create, :article => {}, :use_route => :cornerstone
|
96
|
+
response.should redirect_to(admin_article_path(mock_article))
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
context "with invalid parameters" do
|
102
|
+
before do
|
103
|
+
Cornerstone::Article.stub!(:new) {mock_article(:save => false)}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "exposes a newly created but unsaved article as @article" do
|
107
|
+
post :create, :article => {}, :use_route => :cornerstone
|
108
|
+
assigns(:article).should equal(mock_article)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "exposes article categories for selection as @categories" do
|
112
|
+
Cornerstone::Category.should_receive(:articles) {mock_category}
|
113
|
+
post :create, :article => {}, :use_route => :cornerstone
|
114
|
+
assigns(:categories).should equal(mock_category)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "re-renders the 'new' template" do
|
118
|
+
post :create, :article => {}, :use_route => :cornerstone
|
119
|
+
response.should render_template(:new)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
context "with a normal user" do
|
124
|
+
it "raises the unauthorized error" do
|
125
|
+
lambda {
|
126
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
127
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "GET edit" do
|
133
|
+
context "with an administrator" do
|
134
|
+
before do
|
135
|
+
sign_in_admin
|
136
|
+
end
|
137
|
+
it "exposes the requested article as @article" do
|
138
|
+
Cornerstone::Article.should_receive(:find).with("37") {mock_article}
|
139
|
+
get :edit, :id => "37", :use_route => :cornerstone
|
140
|
+
assigns[:article].should equal(mock_article)
|
141
|
+
end
|
142
|
+
it "exposes article categories for selection as @categories" do
|
143
|
+
Cornerstone::Article.should_receive(:find).with("37") {mock_article}
|
144
|
+
Cornerstone::Category.should_receive(:articles) {mock_category}
|
145
|
+
get :edit, :id => "37", :use_route => :cornerstone
|
146
|
+
assigns(:categories).should equal(mock_category)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
context "with a normal user" do
|
150
|
+
it "raises the unauthorized error" do
|
151
|
+
lambda {
|
152
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
153
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "PUT update" do
|
159
|
+
context "with an administrator" do
|
160
|
+
before do
|
161
|
+
sign_in_admin
|
162
|
+
end
|
163
|
+
it "exposes the requested article as @article" do
|
164
|
+
Cornerstone::Article.should_receive(:find).with("37") {mock_article}
|
165
|
+
put :update, :id => "37", :article => {"these" => "params"},
|
166
|
+
:use_route => :cornerstone
|
167
|
+
assigns[:article].should equal(mock_article)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "updates the requested category with the given parameters" do
|
171
|
+
Cornerstone::Article.should_receive(:find).with("37") {mock_article}
|
172
|
+
mock_article.should_receive(:update_attributes).with({"these" => "params"})
|
173
|
+
put :update, :id => "37", :article => {"these" => "params"},
|
174
|
+
:use_route => :cornerstone
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "with valid parameters" do
|
178
|
+
before do
|
179
|
+
Cornerstone::Article.stub(:find).with("37")
|
180
|
+
.and_return(mock_article(:update_attributes => true))
|
181
|
+
end
|
182
|
+
|
183
|
+
it "redirects to the article" do
|
184
|
+
put :update, :id => "37", :article => {"these" => "params"},
|
185
|
+
:use_route => :cornerstone
|
186
|
+
response.should redirect_to(admin_article_path(mock_article))
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "with invalid parameters" do
|
192
|
+
before do
|
193
|
+
Cornerstone::Article.stub(:find).with("37")
|
194
|
+
.and_return(mock_article(:update_attributes => false))
|
195
|
+
end
|
196
|
+
|
197
|
+
it "renders the edit page" do
|
198
|
+
put :update, :id => "37", :article => {}, :use_route => :cornerstone
|
199
|
+
response.should render_template :edit
|
200
|
+
end
|
201
|
+
it "exposes article categories for selection as @categories" do
|
202
|
+
Cornerstone::Category.should_receive(:articles) {mock_category}
|
203
|
+
put :update, :id => "37", :article => {}, :use_route => :cornerstone
|
204
|
+
assigns(:categories).should equal(mock_category)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
context "with a normal user" do
|
209
|
+
it "raises the unauthorized error" do
|
210
|
+
lambda {
|
211
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
212
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "DELETE destroy" do
|
218
|
+
context "with an administrator" do
|
219
|
+
before do
|
220
|
+
sign_in_admin
|
221
|
+
end
|
222
|
+
it "exposes the article as @article" do
|
223
|
+
Cornerstone::Article.should_receive(:find).with("37") {mock_article}
|
224
|
+
delete :destroy, :id => "37", :use_route => :cornerstone
|
225
|
+
assigns[:article].should equal(mock_article)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "redirects to the article list when destroyed" do
|
229
|
+
Cornerstone::Article.stub(:find) {mock_article(:destroy => true)}
|
230
|
+
delete :destroy, :id => "37", :use_route => :cornerstone
|
231
|
+
response.should redirect_to(admin_articles_path)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "redirects to the article list when not destroyed" do
|
235
|
+
Cornerstone::Article.stub(:find) {mock_article(:destroy => false)}
|
236
|
+
delete :destroy, :id => "37", :use_route => :cornerstone
|
237
|
+
response.should redirect_to(admin_articles_path)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
context "with a normal user" do
|
241
|
+
it "raises the unauthorized error" do
|
242
|
+
lambda {
|
243
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
244
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cornerstone::Admin::CategoriesController do
|
4
|
+
|
5
|
+
def mock_category(stubs={})
|
6
|
+
@mock_category ||= mock_model(Cornerstone::Category, stubs).as_null_object
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "GET index" do
|
10
|
+
context "with an administrator" do
|
11
|
+
before do
|
12
|
+
sign_in_admin
|
13
|
+
end
|
14
|
+
it "exposes all discussion categories as @discussion_categories" do
|
15
|
+
Cornerstone::Category.should_receive(:discussions) {[mock_category]}
|
16
|
+
get :index, :use_route => :cornerstone
|
17
|
+
assigns[:discussion_categories].should == [mock_category]
|
18
|
+
end
|
19
|
+
it "exposes all article categories as @article_categories" do
|
20
|
+
Cornerstone::Category.should_receive(:articles) {[mock_category]}
|
21
|
+
get :index, :use_route => :cornerstone
|
22
|
+
assigns[:article_categories].should == [mock_category]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context "with a normal user" do
|
26
|
+
it "raises the unauthorized error" do
|
27
|
+
lambda {
|
28
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
29
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "GET new" do
|
35
|
+
context "with an administrator" do
|
36
|
+
before do
|
37
|
+
sign_in_admin
|
38
|
+
end
|
39
|
+
it "exposes a new category as @category" do
|
40
|
+
Cornerstone::Category.should_receive(:new) {mock_category}
|
41
|
+
get :new, :use_route => :cornerstone
|
42
|
+
assigns[:category].should == mock_category
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context "with a normal user" do
|
46
|
+
it "raises the unauthorized error" do
|
47
|
+
lambda {
|
48
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
49
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "POST create" do
|
55
|
+
context "with an administrator" do
|
56
|
+
before do
|
57
|
+
sign_in_admin
|
58
|
+
end
|
59
|
+
context "with valid parameters" do
|
60
|
+
it "exposes a newly created category as @category" do
|
61
|
+
Cornerstone::Category.should_receive(:new)
|
62
|
+
.with({'these' => 'params'}) {mock_category :save => true}
|
63
|
+
post :create, :category => {:these => 'params'}, :use_route => :cornerstone
|
64
|
+
assigns(:category).should equal(mock_category)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "redirects to the category list" do
|
68
|
+
Cornerstone::Category.stub!(:new) {mock_category(:save => true)}
|
69
|
+
post :create, :category => {}, :use_route => :cornerstone
|
70
|
+
response.should redirect_to(admin_categories_path)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with invalid parameters" do
|
75
|
+
it "exposes a newly created but unsaved category as @category" do
|
76
|
+
Cornerstone::Category.stub!(:new)
|
77
|
+
.with({'these' => 'params'}) {mock_category(:save => false)}
|
78
|
+
post :create, :category => {:these => 'params'}, :use_route => :cornerstone
|
79
|
+
assigns(:category).should equal(mock_category)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "re-renders the 'new' template" do
|
83
|
+
Cornerstone::Category.stub!(:new) {mock_category(:save => false)}
|
84
|
+
post :create, :category => {}, :use_route => :cornerstone
|
85
|
+
response.should render_template(:new)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
context "with a normal user" do
|
90
|
+
it "raises the unauthorized error" do
|
91
|
+
lambda {
|
92
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
93
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "GET edit" do
|
99
|
+
context "with an administrator" do
|
100
|
+
before do
|
101
|
+
sign_in_admin
|
102
|
+
end
|
103
|
+
it "exposes the requested category as @category" do
|
104
|
+
Cornerstone::Category.should_receive(:find).with("37") {mock_category}
|
105
|
+
get :edit, :id => "37", :use_route => :cornerstone
|
106
|
+
assigns[:category].should equal(mock_category)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
context "with a normal user" do
|
110
|
+
it "raises the unauthorized error" do
|
111
|
+
lambda {
|
112
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
113
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "PUT update" do
|
119
|
+
context "with an administrator" do
|
120
|
+
before do
|
121
|
+
sign_in_admin
|
122
|
+
end
|
123
|
+
it "exposes the requested category as @category" do
|
124
|
+
Cornerstone::Category.should_receive(:find).with("37") {mock_category}
|
125
|
+
put :update, :id => "37", :category => {"these" => "params"},
|
126
|
+
:use_route => :cornerstone
|
127
|
+
assigns[:category].should equal(mock_category)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "updates the requested category with the given parameters" do
|
131
|
+
Cornerstone::Category.should_receive(:find).with("37") {mock_category}
|
132
|
+
mock_category.should_receive(:update_attributes).with({"these" => "params"})
|
133
|
+
put :update, :id => "37", :category => {"these" => "params"},
|
134
|
+
:use_route => :cornerstone
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "with valid parameters" do
|
138
|
+
before do
|
139
|
+
Cornerstone::Category.stub(:find).with("37")
|
140
|
+
.and_return(mock_category(:update_attributes => true))
|
141
|
+
end
|
142
|
+
|
143
|
+
it "redirects to the category list" do
|
144
|
+
put :update, :id => "37", :category => {"these" => "params"},
|
145
|
+
:use_route => :cornerstone
|
146
|
+
response.should redirect_to(admin_categories_path)
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "with invalid parameters" do
|
152
|
+
before do
|
153
|
+
Cornerstone::Category.stub(:find).with("37")
|
154
|
+
.and_return(mock_category(:update_attributes => false))
|
155
|
+
end
|
156
|
+
it "renders the edit page" do
|
157
|
+
put :update, :id => "37", :category => {}, :use_route => :cornerstone
|
158
|
+
response.should render_template :edit
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
context "with a normal user" do
|
163
|
+
it "raises the unauthorized error" do
|
164
|
+
lambda {
|
165
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
166
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "DELETE destroy" do
|
172
|
+
context "with an administrator" do
|
173
|
+
before do
|
174
|
+
sign_in_admin
|
175
|
+
end
|
176
|
+
it "exposes the category as @category" do
|
177
|
+
Cornerstone::Category.should_receive(:find).with("37") {mock_category}
|
178
|
+
delete :destroy, :id => "37", :use_route => :cornerstone
|
179
|
+
assigns[:category].should equal(mock_category)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "redirects to the category list when destroyed" do
|
183
|
+
Cornerstone::Category.stub(:find) {mock_category(:destroy => true)}
|
184
|
+
delete :destroy, :id => "37", :use_route => :cornerstone
|
185
|
+
response.should redirect_to(admin_categories_path)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "redirects to the category list when not destroyed" do
|
189
|
+
Cornerstone::Category.stub(:find) {mock_category(:destroy => false)}
|
190
|
+
delete :destroy, :id => "37", :use_route => :cornerstone
|
191
|
+
response.should redirect_to(admin_categories_path)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
context "with a normal user" do
|
195
|
+
it "raises the unauthorized error" do
|
196
|
+
lambda {
|
197
|
+
get :edit, :id => "2", :use_route => :cornerstone
|
198
|
+
}.should raise_error(Cornerstone::AccessDenied)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
end
|
205
|
+
|