sunrise-scaffold 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/Rakefile +0 -20
  2. data/lib/generators/sunrise/scaffold/manage_generator.rb +2 -2
  3. data/lib/generators/sunrise/scaffold/templates/multiplay/controller.rb +4 -9
  4. data/lib/generators/sunrise/scaffold/templates/multiplay/spec/controller_spec.rb +96 -0
  5. data/lib/generators/sunrise/scaffold/templates/multiplay/views/index.html.erb +5 -1
  6. data/lib/generators/sunrise/scaffold/templates/multiplay/views/item.html.erb +7 -2
  7. data/lib/generators/sunrise/scaffold/templates/multiplay/views/model_filter.html.erb +11 -9
  8. data/lib/generators/sunrise/scaffold/templates/single/controller.rb +4 -9
  9. data/lib/generators/sunrise/scaffold/templates/single/spec/controller_spec.rb +94 -0
  10. data/lib/generators/sunrise/scaffold/templates/single/views/index.html.erb +7 -1
  11. data/lib/generators/sunrise/scaffold/templates/single/views/item.html.erb +8 -3
  12. data/lib/generators/sunrise/scaffold/templates/single/views/model_filter.html.erb +12 -11
  13. data/lib/sunrise/scaffold/version.rb +1 -1
  14. data/test/dummy/Rakefile +7 -0
  15. data/test/dummy/app/controllers/application_controller.rb +3 -0
  16. data/test/dummy/app/helpers/application_helper.rb +2 -0
  17. data/test/dummy/app/models/comment.rb +3 -0
  18. data/test/dummy/app/models/post.rb +3 -0
  19. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/test/dummy/config/application.rb +45 -0
  21. data/test/dummy/config/boot.rb +10 -0
  22. data/test/dummy/config/database.yml +22 -0
  23. data/test/dummy/config/environment.rb +5 -0
  24. data/test/dummy/config/environments/development.rb +26 -0
  25. data/test/dummy/config/environments/production.rb +49 -0
  26. data/test/dummy/config/environments/test.rb +35 -0
  27. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/test/dummy/config/initializers/inflections.rb +10 -0
  29. data/test/dummy/config/initializers/mime_types.rb +5 -0
  30. data/test/dummy/config/initializers/secret_token.rb +7 -0
  31. data/test/dummy/config/initializers/session_store.rb +8 -0
  32. data/test/dummy/config/locales/en.yml +5 -0
  33. data/test/dummy/config/routes.rb +58 -0
  34. data/test/dummy/config.ru +4 -0
  35. data/test/dummy/db/migrate/20110722084440_create_posts.rb +14 -0
  36. data/test/dummy/db/migrate/20110722085934_create_comments.rb +15 -0
  37. data/test/dummy/db/test.sqlite3 +0 -0
  38. data/test/dummy/log/development.log +0 -0
  39. data/test/dummy/log/production.log +0 -0
  40. data/test/dummy/log/server.log +0 -0
  41. data/test/dummy/log/test.log +135 -0
  42. data/test/dummy/public/404.html +26 -0
  43. data/test/dummy/public/422.html +26 -0
  44. data/test/dummy/public/500.html +26 -0
  45. data/test/dummy/public/favicon.ico +0 -0
  46. data/test/dummy/public/javascripts/application.js +2 -0
  47. data/test/dummy/public/javascripts/controls.js +965 -0
  48. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  49. data/test/dummy/public/javascripts/effects.js +1123 -0
  50. data/test/dummy/public/javascripts/prototype.js +6001 -0
  51. data/test/dummy/public/javascripts/rails.js +191 -0
  52. data/test/dummy/script/rails +6 -0
  53. data/test/generators/manage_generator_test.rb +32 -0
  54. data/test/integration/navigation_test.rb +7 -0
  55. data/test/support/integration_case.rb +4 -0
  56. data/test/test_helper.rb +29 -0
  57. data/test/tmp/app/controllers/manage/posts_controller.rb +26 -0
  58. data/test/tmp/app/helpers/manage/posts_helper.rb +2 -0
  59. data/test/tmp/app/views/manage/posts/_form.html.erb +18 -0
  60. data/test/tmp/app/views/manage/posts/_model_filter.html.erb +34 -0
  61. data/test/tmp/app/views/manage/posts/_post.html.erb +32 -0
  62. data/test/tmp/app/views/manage/posts/edit.html.erb +6 -0
  63. data/test/tmp/app/views/manage/posts/index.html.erb +36 -0
  64. data/test/tmp/app/views/manage/posts/new.html.erb +6 -0
  65. data/test/tmp/app/views/manage/posts/show.html.erb +29 -0
  66. data/test/tmp/spec/controllers/manage/posts_controller_spec.rb +94 -0
  67. metadata +137 -35
  68. data/Gemfile.lock +0 -75
  69. data/lib/generators/sunrise/scaffold/templates/multiplay/functional_test.rb +0 -103
  70. data/lib/generators/sunrise/scaffold/templates/single/functional_test.rb +0 -98
@@ -0,0 +1,191 @@
1
+ (function() {
2
+ // Technique from Juriy Zaytsev
3
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
+ function isEventSupported(eventName) {
5
+ var el = document.createElement('div');
6
+ eventName = 'on' + eventName;
7
+ var isSupported = (eventName in el);
8
+ if (!isSupported) {
9
+ el.setAttribute(eventName, 'return;');
10
+ isSupported = typeof el[eventName] == 'function';
11
+ }
12
+ el = null;
13
+ return isSupported;
14
+ }
15
+
16
+ function isForm(element) {
17
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
+ }
19
+
20
+ function isInput(element) {
21
+ if (Object.isElement(element)) {
22
+ var name = element.nodeName.toUpperCase()
23
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
+ }
25
+ else return false
26
+ }
27
+
28
+ var submitBubbles = isEventSupported('submit'),
29
+ changeBubbles = isEventSupported('change')
30
+
31
+ if (!submitBubbles || !changeBubbles) {
32
+ // augment the Event.Handler class to observe custom events when needed
33
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
+ function(init, element, eventName, selector, callback) {
35
+ init(element, eventName, selector, callback)
36
+ // is the handler being attached to an element that doesn't support this event?
37
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
+ // "submit" => "emulated:submit"
40
+ this.eventName = 'emulated:' + this.eventName
41
+ }
42
+ }
43
+ )
44
+ }
45
+
46
+ if (!submitBubbles) {
47
+ // discover forms on the page by observing focus events which always bubble
48
+ document.on('focusin', 'form', function(focusEvent, form) {
49
+ // special handler for the real "submit" event (one-time operation)
50
+ if (!form.retrieve('emulated:submit')) {
51
+ form.on('submit', function(submitEvent) {
52
+ var emulated = form.fire('emulated:submit', submitEvent, true)
53
+ // if custom event received preventDefault, cancel the real one too
54
+ if (emulated.returnValue === false) submitEvent.preventDefault()
55
+ })
56
+ form.store('emulated:submit', true)
57
+ }
58
+ })
59
+ }
60
+
61
+ if (!changeBubbles) {
62
+ // discover form inputs on the page
63
+ document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
+ // special handler for real "change" events
65
+ if (!input.retrieve('emulated:change')) {
66
+ input.on('change', function(changeEvent) {
67
+ input.fire('emulated:change', changeEvent, true)
68
+ })
69
+ input.store('emulated:change', true)
70
+ }
71
+ })
72
+ }
73
+
74
+ function handleRemote(element) {
75
+ var method, url, params;
76
+
77
+ var event = element.fire("ajax:before");
78
+ if (event.stopped) return false;
79
+
80
+ if (element.tagName.toLowerCase() === 'form') {
81
+ method = element.readAttribute('method') || 'post';
82
+ url = element.readAttribute('action');
83
+ params = element.serialize();
84
+ } else {
85
+ method = element.readAttribute('data-method') || 'get';
86
+ url = element.readAttribute('href');
87
+ params = {};
88
+ }
89
+
90
+ new Ajax.Request(url, {
91
+ method: method,
92
+ parameters: params,
93
+ evalScripts: true,
94
+
95
+ onComplete: function(request) { element.fire("ajax:complete", request); },
96
+ onSuccess: function(request) { element.fire("ajax:success", request); },
97
+ onFailure: function(request) { element.fire("ajax:failure", request); }
98
+ });
99
+
100
+ element.fire("ajax:after");
101
+ }
102
+
103
+ function handleMethod(element) {
104
+ var method = element.readAttribute('data-method'),
105
+ url = element.readAttribute('href'),
106
+ csrf_param = $$('meta[name=csrf-param]')[0],
107
+ csrf_token = $$('meta[name=csrf-token]')[0];
108
+
109
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
+ element.parentNode.insert(form);
111
+
112
+ if (method !== 'post') {
113
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
+ form.insert(field);
115
+ }
116
+
117
+ if (csrf_param) {
118
+ var param = csrf_param.readAttribute('content'),
119
+ token = csrf_token.readAttribute('content'),
120
+ field = new Element('input', { type: 'hidden', name: param, value: token });
121
+ form.insert(field);
122
+ }
123
+
124
+ form.submit();
125
+ }
126
+
127
+
128
+ document.on("click", "*[data-confirm]", function(event, element) {
129
+ var message = element.readAttribute('data-confirm');
130
+ if (!confirm(message)) event.stop();
131
+ });
132
+
133
+ document.on("click", "a[data-remote]", function(event, element) {
134
+ if (event.stopped) return;
135
+ handleRemote(element);
136
+ event.stop();
137
+ });
138
+
139
+ document.on("click", "a[data-method]", function(event, element) {
140
+ if (event.stopped) return;
141
+ handleMethod(element);
142
+ event.stop();
143
+ });
144
+
145
+ document.on("submit", function(event) {
146
+ var element = event.findElement(),
147
+ message = element.readAttribute('data-confirm');
148
+ if (message && !confirm(message)) {
149
+ event.stop();
150
+ return false;
151
+ }
152
+
153
+ var inputs = element.select("input[type=submit][data-disable-with]");
154
+ inputs.each(function(input) {
155
+ input.disabled = true;
156
+ input.writeAttribute('data-original-value', input.value);
157
+ input.value = input.readAttribute('data-disable-with');
158
+ });
159
+
160
+ var element = event.findElement("form[data-remote]");
161
+ if (element) {
162
+ handleRemote(element);
163
+ event.stop();
164
+ }
165
+ });
166
+
167
+ document.on("ajax:after", "form", function(event, element) {
168
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
+ inputs.each(function(input) {
170
+ input.value = input.readAttribute('data-original-value');
171
+ input.removeAttribute('data-original-value');
172
+ input.disabled = false;
173
+ });
174
+ });
175
+
176
+ Ajax.Responders.register({
177
+ onCreate: function(request) {
178
+ var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
179
+
180
+ if (csrf_meta_tag) {
181
+ var header = 'X-CSRF-Token',
182
+ token = csrf_meta_tag.readAttribute('content');
183
+
184
+ if (!request.options.requestHeaders) {
185
+ request.options.requestHeaders = {};
186
+ }
187
+ request.options.requestHeaders[header] = token;
188
+ }
189
+ }
190
+ });
191
+ })();
@@ -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,32 @@
1
+ require "test_helper"
2
+
3
+ class ManageGeneratorTest < Rails::Generators::TestCase
4
+ tests Sunrise::Scaffold::ManageGenerator
5
+ destination File.expand_path("../../tmp", __FILE__)
6
+ setup :prepare_destination
7
+
8
+ test "Generate manage templates for single model" do
9
+ run_generator %w(post)
10
+
11
+ assert_file "app/controllers/manage/posts_controller.rb"
12
+ assert_file "app/helpers/manage/posts_helper.rb"
13
+ assert_file "spec/controllers/manage/posts_controller_spec.rb"
14
+
15
+ # Views
16
+ ["edit", "_form", "index", "_model_filter", "new", "_post", "show"].each do |file|
17
+ assert_file "app/views/manage/posts/#{file}.html.erb"
18
+ end
19
+ end
20
+
21
+ test "Generate manage templates for multiplay models" do
22
+ run_generator %w(comment --parent=post)
23
+
24
+ assert_file "app/controllers/manage/comments_controller.rb"
25
+ assert_file "app/helpers/manage/comments_helper.rb"
26
+ assert_file "spec/controllers/manage/comments_controller_spec.rb"
27
+ # Views
28
+ ["edit", "_form", "index", "_model_filter", "new", "_comment", "show"].each do |file|
29
+ assert_file "app/views/manage/comments/#{file}.html.erb"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActiveSupport::IntegrationCase
4
+ test "truth" do
5
+ assert_kind_of Dummy::Application, Rails.application
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # Define a bare test case to use with Capybara
2
+ class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
3
+ include Rails.application.routes.url_helpers
4
+ end
@@ -0,0 +1,29 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ # Clear tmp folder
5
+ require "fileutils"
6
+ FileUtils.rm_r "#{File.dirname(__FILE__)}/test/tmp", :force => true
7
+
8
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
9
+ require "rails/test_help"
10
+
11
+ ActionMailer::Base.delivery_method = :test
12
+ ActionMailer::Base.perform_deliveries = true
13
+ ActionMailer::Base.default_url_options[:host] = "test.com"
14
+
15
+ Rails.backtrace_cleaner.remove_silencers!
16
+
17
+ # Run any available migration
18
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
19
+
20
+ # Load support files
21
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
22
+
23
+ # For generators
24
+ require "rails/generators/test_case"
25
+ require "generators/sunrise/scaffold/manage_generator"
26
+
27
+ # Clear temp folder
28
+ require 'fileutils'
29
+ FileUtils.rm_r File.expand_path("../tmp", __FILE__), :force => true
@@ -0,0 +1,26 @@
1
+ class Manage::PostsController < Manage::BaseController
2
+ inherit_resources
3
+
4
+ load_and_authorize_resource :class => Post
5
+
6
+ has_scope :with_title, :as => :title, :only => :index
7
+ order_by :created_at, :updated_at
8
+
9
+ def create
10
+ create!{ manage_posts_path }
11
+ end
12
+
13
+ def update
14
+ update!{ manage_posts_path }
15
+ end
16
+
17
+ def destroy
18
+ destroy!{ manage_posts_path }
19
+ end
20
+
21
+ protected
22
+
23
+ def collection
24
+ @posts = (@posts || end_of_association_chain).order(search_filter.order).page(params[:page])
25
+ end
26
+ end
@@ -0,0 +1,2 @@
1
+ module Manage::PostsHelper
2
+ end
@@ -0,0 +1,18 @@
1
+ <%= manage_form_for @post do |f| %>
2
+
3
+
4
+ <div class="edit-cont">
5
+ <div class="inputs-bl">
6
+
7
+ <%= f.input :created_at %>
8
+
9
+ <%= f.input :title %>
10
+
11
+ <%= f.input :updated_at %>
12
+
13
+ <%= f.input :content %>
14
+ </div>
15
+ </div>
16
+
17
+ <%= f.button :submit %>
18
+ <% end %>
@@ -0,0 +1,34 @@
1
+ <div class="bot-bg">
2
+ <div class="filt-bl">
3
+ <%= link_to_function t('manage.model_filter.title'), "Manage.toggle_element('block_filter')", :class=>"dark-arr" %>
4
+
5
+ <%= t('manage.model_filter.total_count') %>: <%= @posts.total_count %>
6
+
7
+ <%= cookie_content_tag(:div, :id=>"block_filter", :class=>"filt") do %>
8
+ <%= form_for search_filter, :url => manage_posts_path, :html => { :method => :get } do |f| %>
9
+ <% controller.scopes_configuration.each do |key, value| %>
10
+ <%= f.label value[:as], t(value[:as], :scope => "activerecord.attributes.post") %>
11
+ <%= f.text_field value[:as], :class => "text", :name => value[:as] %>
12
+ <% end %>
13
+
14
+ <div class="buts">
15
+ <%= content_tag(:button, :value=>"search", :type=>"submit", :name=>"commit", :class=>"gr cupid-green") do %>
16
+ <%= t('manage.model_filter.search') %>
17
+ <% end %>
18
+
19
+ <%= link_to t('manage.model_filter.clear'), manage_posts_path, :class=>"erase" %>
20
+ </div>
21
+ <% end %>
22
+ <% end %>
23
+ </div>
24
+ <div class="sort">
25
+ <label><%= t('manage.sort') %></label>
26
+ <div class="select-input"><%= link_to_function t(search_filter.current_order, :scope => "manage.posts.sort"), "SelectList.toggle(event)", :class=>"corn", :id=>'sort_select' %></div>
27
+ <div id='sort_select_list' class="select-list" style='display:none;'>
28
+ <% controller.orders_configuration.each do |key, value| %>
29
+ <%= link_to_sort(t("#{key}_desc", :scope => "manage.posts.sort"), :name => key, :order_type=>'desc') %>
30
+ <%= link_to_sort(t("#{key}_asc", :scope => "manage.posts.sort"), :name => key, :order_type=>'asc') %>
31
+ <% end %>
32
+ </div>
33
+ </div>
34
+ </div>
@@ -0,0 +1,32 @@
1
+ <%= content_tag(:div, :id=>dom_id(post), :class=>"dinamic-bl") do %>
2
+ <div class="act-bl" style="display:none;">
3
+ <% if can? :update, post, :context => :manage %>
4
+ <%= link_to manage_icon("edit"), edit_manage_post_path(:id=>post.id), :class=>"icons" %>
5
+ <% end -%>
6
+
7
+ <% if can? :delete, post, :context => :manage %>
8
+ <%= link_to manage_icon("delete"), manage_post_path(:id=>post.id),
9
+ :method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
10
+ <% end -%>
11
+ </div>
12
+
13
+ <div class="bot-bg">
14
+ <div class="dinamic-container">
15
+ <div class="right-data">
16
+ <div class="right-data-cont">
17
+ <div class="dinamic-inner">
18
+ <div class="r-block">
19
+ <div class="r-block-cont">
20
+ <%= link_to post.title, edit_manage_post_path(:id=>post.id), :class=>"title" %>
21
+ </div>
22
+ </div>
23
+ <!--<div class="l-block"> ava img </div>-->
24
+ </div>
25
+ </div>
26
+ </div>
27
+ <div class="left-data">
28
+ <span class="data"><%= raw I18n.l(post.created_at, :format=>"<span>%d/%m</span>%Y") %></span>
29
+ </div>
30
+ </div>
31
+ </div>
32
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%= t('manage.edit') %>:</div>
4
+ <%= render :partial => 'manage/posts/form' %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,36 @@
1
+ <div class="duo-bl">
2
+ <div class="left-part">
3
+ <div class="content">
4
+ <div class="row-container">
5
+ <div class="white-row">
6
+ <div class="r-corn">
7
+ <%= link_to t('manage.menu.posts'), manage_posts_path, :class=>"dark-text" %>
8
+ <div class="act-bl">
9
+ <% if can? :create, Post, :context => :manage %>
10
+ <%= link_to t('manage.add'), new_manage_post_path, :class=>"create" %>
11
+ <% end -%>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ </div>
16
+
17
+ <div id="posts" class="stage">
18
+ <%= render :partial=>"manage/posts/post", :collection=>@posts %>
19
+ <%= paginate @posts, :theme => 'manage' %>
20
+ </div>
21
+
22
+ <script type='text/javascript'>
23
+ $(document).ready(function(){
24
+ Manage.init_collection('posts', 'dinamic-bl');
25
+ });
26
+ </script>
27
+
28
+ </div>
29
+ </div>
30
+
31
+ <div class="right-part">
32
+ <div class="filter-right">
33
+ <%= render :partial=>"manage/posts/model_filter" %>
34
+ </div>
35
+ </div>
36
+ </div>
@@ -0,0 +1,6 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%= t('manage.add') %>:</div>
4
+ <%= render :partial => 'manage/posts/form' %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,29 @@
1
+ <div class="buttons">
2
+ <div class="back-but-bl">
3
+ <%= link_to content_tag(:span, t('manage.menu.posts')), manage_posts_path, :class=>"back" %>
4
+ </div>
5
+
6
+ <div class="act-bl">
7
+ <%= link_to image_tag("manage/ico_edit.gif", :title=>t('manage.edit')), edit_manage_post_path(:id=>@post.id), :class=>"icons" %>
8
+
9
+ <%= link_to image_tag("manage/ico_del.gif", :title=>t('manage.delete')), manage_post_path(:id=>@post.id), :method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
10
+ </div>
11
+ </div>
12
+
13
+ <div class="edit-bl">
14
+ <div class="bot-bg">
15
+ <div class="block-title"><%= @post.title %>:</div>
16
+ <div class="edit-cont">
17
+ <table border="0" cellspacing="0" cellpadding="0" class="page-info">
18
+ <tbody>
19
+ <% @post.attributes.each do |attribute, value| %>
20
+ <tr>
21
+ <td><strong><%= attribute %></strong></td>
22
+ <td><%= value %></td>
23
+ </tr>
24
+ <% end %>
25
+ </tbody>
26
+ </table>
27
+ </div>
28
+ </div>
29
+ </div>
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Manage::PostsController do
4
+ render_views
5
+
6
+ context "administrator" do
7
+ login_admin
8
+
9
+ before(:each) do
10
+ @attrs = FactoryGirl.attributes_for(:post)
11
+ end
12
+
13
+ it "should render new action" do
14
+ get :new
15
+ response.should be_success
16
+ response.should render_template("new")
17
+ end
18
+
19
+ it "should create new post" do
20
+ lambda {
21
+ post :create, :post => @attrs
22
+ }.should change { Post.count }.by(1)
23
+ end
24
+
25
+ context "exists default post" do
26
+ before(:each) do
27
+ @post = FactoryGirl.create(:post)
28
+ end
29
+
30
+ it "should render index action" do
31
+ get :index
32
+ assigns(:posts).should include(@post)
33
+ response.should render_template('index')
34
+ end
35
+
36
+ it "should render edit action" do
37
+ controller.should_receive :edit
38
+ get :edit, :id => @post.id
39
+ end
40
+
41
+ it "should update post" do
42
+ put :update, :id => @post.id, :post => @attrs
43
+ assigns(:post).should be_valid
44
+ response.should redirect_to(manage_posts_path)
45
+ end
46
+
47
+ it "should destroy post" do
48
+ lambda {
49
+ delete :destroy, :id => @post.id
50
+ }.should change { Post.count }.by(-1)
51
+ end
52
+ end
53
+ end
54
+
55
+ context "anonymous user" do
56
+ user_logout
57
+
58
+ it "should not render index action" do
59
+ controller.should_not_receive :index
60
+ get :index
61
+ end
62
+
63
+ it "should not render new action" do
64
+ controller.should_not_receive :new
65
+ get :new
66
+ end
67
+
68
+ it "should not render create action" do
69
+ controller.should_not_receive :create
70
+ post :create
71
+ end
72
+
73
+ context "with exists post" do
74
+ before(:each) do
75
+ @post = FactoryGirl.create(:post)
76
+ end
77
+
78
+ it "should not render edit action" do
79
+ controller.should_not_receive :edit
80
+ get :edit, :id => @post.id
81
+ end
82
+
83
+ it "should not render update action" do
84
+ controller.should_not_receive :update
85
+ put :update, :id => @post.id
86
+ end
87
+
88
+ it "should not render destroy action" do
89
+ controller.should_not_receive :destroy
90
+ delete :destroy, :id => @post.id
91
+ end
92
+ end
93
+ end
94
+ end