This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| 44316d0a » | ian | 2007-10-24 | 1 | require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper')) | |
| 2 | require File.expand_path(File.join(File.dirname(__FILE__), '../app')) | ||||
| 3 | |||||
| 4 | module LoadEnclosingResourcesSpecHelper | ||||
| 5 | def setup_tags_controller(options = {}) | ||||
| 6 | @klass = Class.new(ActionController::Base) | ||||
| 7 | @klass.resources_controller_for :tags, options | ||||
| 8 | setup_common | ||||
| 9 | end | ||||
| 10 | |||||
| 11 | def setup_common | ||||
| 12 | @controller = @klass.new | ||||
| 13 | # stub :load_enclosing_resource_from_specification, increase enclosing_resources by one, and return a mock resource | ||||
| 14 | @controller.stub!(:load_enclosing_resource_from_specification).and_return do |name, _| | ||||
| 15 | returning mock("resource: #{name}") do |resource| | ||||
| 16 | @controller.enclosing_resources << resource | ||||
| 17 | end | ||||
| 18 | end | ||||
| 19 | end | ||||
| 20 | end | ||||
| 21 | |||||
| 22 | describe "#load_enclosing_resources for resources_controller_for :tags (when route_enclosing_names is [['users', false]])" do | ||||
| 23 | include LoadEnclosingResourcesSpecHelper | ||||
| 24 | |||||
| 25 | before do | ||||
| 26 | setup_tags_controller | ||||
| 27 | @controller.stub!(:route_enclosing_names).and_return [['users', false]] | ||||
| 28 | end | ||||
| 29 | |||||
| 30 | it "should call load_wildcard once" do | ||||
| 31 | @controller.should_receive(:load_wildcard).once | ||||
| 32 | @controller.send(:load_enclosing_resources) | ||||
| 33 | end | ||||
| 34 | |||||
| 1b8be92d » | ian | 2007-11-06 | 35 | it "should call Specification.new('user', :singleton => false, :as => nil)" do | |
| 36 | Ardes::ResourcesController::Specification.should_receive(:new).with('user', :singleton => false, :as => nil) | ||||
| 44316d0a » | ian | 2007-10-24 | 37 | @controller.send(:load_enclosing_resources) | |
| 38 | end | ||||
| 39 | end | ||||
| 40 | |||||
| 41 | describe "#load_enclosing_resources for resources_controller_for :tags, with :account mapping (when route_enclosing_names is [['account', true]])" do | ||||
| 42 | include LoadEnclosingResourcesSpecHelper | ||||
| 43 | |||||
| 44 | before do | ||||
| 45 | setup_tags_controller | ||||
| 46 | @klass.map_resource :account, :singleton => true, :class => User | ||||
| 47 | @account_spec = @controller.resource_specification_map['account'] | ||||
| 48 | @controller.stub!(:route_enclosing_names).and_return [['account', true]] | ||||
| 49 | end | ||||
| 50 | |||||
| 51 | it "should call load_wildcard once" do | ||||
| 52 | @controller.should_receive(:load_wildcard).once | ||||
| 53 | @controller.send(:load_enclosing_resources) | ||||
| 54 | end | ||||
| 55 | |||||
| 56 | it "should call load_enclosing_resource_from_specification with account specification" do | ||||
| 1b8be92d » | ian | 2007-11-06 | 57 | @controller.should_receive(:load_enclosing_resource_from_specification).with(@account_spec) | |
| 44316d0a » | ian | 2007-10-24 | 58 | @controller.send(:load_enclosing_resources) | |
| 59 | end | ||||
| 60 | |||||
| 61 | it "should not call Specification.new" do | ||||
| 62 | Ardes::ResourcesController::Specification.should_not_receive(:new) | ||||
| 63 | @controller.send(:load_enclosing_resources) | ||||
| 64 | end | ||||
| 65 | end | ||||
| 66 | |||||
| 67 | describe "#load_enclosing_resources for resources_controller_for :tags (when route_enclosing_names is [['users', false], ['forums', false]])" do | ||||
| 68 | include LoadEnclosingResourcesSpecHelper | ||||
| 69 | |||||
| 70 | before do | ||||
| 71 | setup_tags_controller | ||||
| 72 | @controller.stub!(:route_enclosing_names).and_return [['users', false], ['forums', false]] | ||||
| 73 | end | ||||
| 74 | |||||
| 75 | it "should call load_wildcard twice" do | ||||
| 76 | @controller.should_receive(:load_wildcard).twice | ||||
| 77 | @controller.send(:load_enclosing_resources) | ||||
| 78 | end | ||||
| 79 | |||||
| 1b8be92d » | ian | 2007-11-06 | 80 | it "should call Specification.new with ('user', :singleton => false, :as => nil), then ('forum', :singleton => false, :as => nil)" do | |
| 81 | Ardes::ResourcesController::Specification.should_receive(:new).with('user', :singleton => false, :as => nil).ordered | ||||
| 82 | Ardes::ResourcesController::Specification.should_receive(:new).with('forum', :singleton => false, :as => nil).ordered | ||||
| 44316d0a » | ian | 2007-10-24 | 83 | @controller.send(:load_enclosing_resources) | |
| 84 | end | ||||
| 85 | end | ||||
| 86 | |||||
| 87 | describe "#load_enclosing_resources for resources_controller_for :tags, :in => ['*', :comment] (when route_enclosing_names is [['comments', false]])" do | ||||
| 88 | include LoadEnclosingResourcesSpecHelper | ||||
| 89 | |||||
| 90 | before do | ||||
| 91 | setup_tags_controller :in => ['*', :comment] | ||||
| 92 | @controller.stub!(:route_enclosing_names).and_return [['comments', false]] | ||||
| 93 | end | ||||
| 94 | |||||
| 95 | it "should not call load_wildcard" do | ||||
| 96 | @controller.should_not_receive(:load_wildcard) | ||||
| 97 | @controller.send(:load_enclosing_resources) | ||||
| 98 | end | ||||
| 99 | |||||
| 100 | it "should not call Specification.new" do | ||||
| 101 | Ardes::ResourcesController::Specification.should_not_receive(:new) | ||||
| 102 | @controller.send(:load_enclosing_resources) | ||||
| 103 | end | ||||
| 104 | end | ||||
| 105 | |||||
| 106 | describe "#load_enclosing_resources for resources_controller_for :tags, :in => ['*', :comment] (when route_enclosing_names is [['users', false], ['forums', false], ['comments', false]])" do | ||||
| 107 | include LoadEnclosingResourcesSpecHelper | ||||
| 108 | |||||
| 109 | before do | ||||
| 110 | setup_tags_controller :in => ['*', :comment] | ||||
| 111 | @controller.stub!(:route_enclosing_names).and_return [['users', false], ['forums', false], ['comments', false]] | ||||
| 112 | end | ||||
| 113 | |||||
| 114 | it "should call load_wildcard twice" do | ||||
| 115 | @controller.should_receive(:load_wildcard).twice | ||||
| 116 | @controller.send(:load_enclosing_resources) | ||||
| 117 | end | ||||
| 118 | |||||
| 1b8be92d » | ian | 2007-11-06 | 119 | it "should call Specification.new with ('user', :singleton => false, :as => nil), then ('forum', :singleton => false, :as => nil)" do | |
| 120 | Ardes::ResourcesController::Specification.should_receive(:new).with('user', :singleton => false, :as => nil).ordered | ||||
| 121 | Ardes::ResourcesController::Specification.should_receive(:new).with('forum', :singleton => false, :as => nil).ordered | ||||
| 44316d0a » | ian | 2007-10-24 | 122 | @controller.send(:load_enclosing_resources) | |
| 123 | end | ||||
| 124 | end | ||||
| 125 | |||||
| 126 | describe "#load_enclosing_resources for resources_controller_for :tags, :in => ['*', :comment] (when route_enclosing_names is [['users', false], ['forums', false], ['special', true], ['comments', false]])" do | ||||
| 127 | include LoadEnclosingResourcesSpecHelper | ||||
| 128 | |||||
| 129 | before do | ||||
| 130 | setup_tags_controller :in => ['*', :comment] | ||||
| 131 | @controller.stub!(:route_enclosing_names).and_return [['users', false], ['forums', false], ['special', true], ['comments', false]] | ||||
| 132 | end | ||||
| 133 | |||||
| 134 | it "should call load_wildcard three times" do | ||||
| 135 | @controller.should_receive(:load_wildcard).exactly(3).times | ||||
| 136 | @controller.send(:load_enclosing_resources) | ||||
| 137 | end | ||||
| 138 | |||||
| 1b8be92d » | ian | 2007-11-06 | 139 | it "should call Specification.new with ('user', :singleton => false, :as => nil), ('forum', :singleton => false, :as => nil), then ('special', :singleton => true, :as => nil)" do | |
| 140 | Ardes::ResourcesController::Specification.should_receive(:new).with('user', :singleton => false, :as => nil).ordered | ||||
| 141 | Ardes::ResourcesController::Specification.should_receive(:new).with('forum', :singleton => false, :as => nil).ordered | ||||
| 142 | Ardes::ResourcesController::Specification.should_receive(:new).with('special', :singleton => true, :as => nil).ordered | ||||
| 44316d0a » | ian | 2007-10-24 | 143 | @controller.send(:load_enclosing_resources) | |
| 144 | end | ||||
| 145 | end | ||||
| 146 | |||||
| 147 | describe "#load_enclosing_resources for resources_controller_for :tags, :in => ['*', '?commentable', :comment] (when route_enclosing_names is [['users', false], ['comments', false]])" do | ||||
| 148 | include LoadEnclosingResourcesSpecHelper | ||||
| 149 | |||||
| 150 | before do | ||||
| 151 | setup_tags_controller :in => ['*', '?commentable', :comment] | ||||
| 152 | @controller.stub!(:route_enclosing_names).and_return [['users', false], ['comments', false]] | ||||
| 153 | end | ||||
| 154 | |||||
| 155 | it "should call load_wildcard once with 'commentable'" do | ||||
| 156 | @controller.should_receive(:load_wildcard).with('commentable').once | ||||
| 157 | @controller.send(:load_enclosing_resources) | ||||
| 158 | end | ||||
| 159 | |||||
| 1b8be92d » | ian | 2007-11-06 | 160 | it "should call Specification.new with ('user', :singleton => false, :as => 'commentable')" do | |
| 161 | Ardes::ResourcesController::Specification.should_receive(:new).with('user', :singleton => false, :as => 'commentable').ordered | ||||
| 44316d0a » | ian | 2007-10-24 | 162 | @controller.send(:load_enclosing_resources) | |
| 163 | end | ||||
| 164 | end | ||||
| 165 | |||||
| 166 | describe "#load_enclosing_resources for resources_controller_for :tags, :in => ['*', '?commentable', :comment] (when route_enclosing_names is [['users', false], ['forums', false], ['comments', false]])" do | ||||
| 167 | include LoadEnclosingResourcesSpecHelper | ||||
| 168 | |||||
| 169 | before do | ||||
| 170 | setup_tags_controller :in => ['*', '?commentable', :comment] | ||||
| 171 | @controller.stub!(:route_enclosing_names).and_return [['users', false], ['forums', false], ['comments', false]] | ||||
| 172 | end | ||||
| 173 | |||||
| 1b8be92d » | ian | 2007-11-06 | 174 | it "should call load_wildcard twice" do | |
| 44316d0a » | ian | 2007-10-24 | 175 | @controller.should_receive(:load_wildcard).with().once.ordered | |
| 176 | @controller.should_receive(:load_wildcard).with('commentable').once.ordered | ||||
| 177 | @controller.send(:load_enclosing_resources) | ||||
| 178 | end | ||||
| 179 | |||||
| 1b8be92d » | ian | 2007-11-06 | 180 | it "should call Specification.new with ('user', :singleton => false, :as => nil), ('forum', :singleton => false, :as => 'commentable')" do | |
| 181 | Ardes::ResourcesController::Specification.should_receive(:new).with('user', :singleton => false, :as => nil).once.ordered | ||||
| 182 | Ardes::ResourcesController::Specification.should_receive(:new).with('forum', :singleton => false, :as => 'commentable').once.ordered | ||||
| 44316d0a » | ian | 2007-10-24 | 183 | @controller.send(:load_enclosing_resources) | |
| 184 | end | ||||
| 185 | end | ||||
| 186 | |||||
| 187 | describe "#load_enclosing_resources for resources_controller_for :tags, :in => ['*', '?commentable', :comment] (when route_enclosing_names is [['users', false], ['forums', false], ['posts', false], ['comments', false]])" do | ||||
| 188 | include LoadEnclosingResourcesSpecHelper | ||||
| 189 | |||||
| 190 | before do | ||||
| 191 | setup_tags_controller :in => ['*', '?commentable', :comment] | ||||
| 192 | @controller.stub!(:route_enclosing_names).and_return [['users', false], ['forums', false], ['posts', false], ['comments', false]] | ||||
| 193 | end | ||||
| 194 | |||||
| 195 | it "should call load_wildcard twice, then once with 'commentable'" do | ||||
| 196 | @controller.should_receive(:load_wildcard).with().twice.ordered | ||||
| 197 | @controller.should_receive(:load_wildcard).with('commentable').once.ordered | ||||
| 198 | @controller.send(:load_enclosing_resources) | ||||
| 199 | end | ||||
| 200 | |||||
| 1b8be92d » | ian | 2007-11-06 | 201 | it "should call Specification.new with ('user', :singleton => false, :as => nil), ('forum', :singleton => false, :as => nil), then ('post', :singleton => false, :as => 'commentable')" do | |
| 202 | Ardes::ResourcesController::Specification.should_receive(:new).with('user', :singleton => false, :as => nil).once.ordered | ||||
| 203 | Ardes::ResourcesController::Specification.should_receive(:new).with('forum', :singleton => false, :as => nil).once.ordered | ||||
| 204 | Ardes::ResourcesController::Specification.should_receive(:new).with('post', :singleton => false, :as => 'commentable').once.ordered | ||||
| 44316d0a » | ian | 2007-10-24 | 205 | @controller.send(:load_enclosing_resources) | |
| 206 | end | ||||
| 207 | end | ||||
| 208 | |||||
| 209 | describe "#load_enclosing_resources for resources_controller_for :tags, :in => ['user', '*', '?taggable'] (when route_enclosing_names is [['users', false], ['comments', false]])" do | ||||
| 210 | include LoadEnclosingResourcesSpecHelper | ||||
| 211 | |||||
| 212 | before do | ||||
| 213 | setup_tags_controller :in => ['user', '*', '?taggable'] | ||||
| 214 | @user_spec = @controller.send(:specifications)[1] | ||||
| 215 | @controller.stub!(:route_enclosing_names).and_return [['users', false], ['comments', false]] | ||||
| 216 | end | ||||
| 217 | |||||
| 218 | it "should call load_enclosing_resource_from_specification with user spec, then load_wildcard once with 'taggable'" do | ||||
| 219 | @controller.should_receive(:load_enclosing_resource_from_specification).with(@user_spec).once.ordered do | ||||
| 220 | returning(mock('user')){|r| @controller.enclosing_resources << r } | ||||
| 221 | end | ||||
| 222 | @controller.should_receive(:load_wildcard).with('taggable').once.ordered | ||||
| 223 | @controller.send(:load_enclosing_resources) | ||||
| 224 | end | ||||
| 225 | |||||
| 1b8be92d » | ian | 2007-11-06 | 226 | it "should call Specification.new with ('comment', :singleton => false, :as => 'taggable')" do | |
| 227 | Ardes::ResourcesController::Specification.should_receive(:new).with('comment', :singleton => false, :as => 'taggable').ordered | ||||
| 44316d0a » | ian | 2007-10-24 | 228 | @controller.send(:load_enclosing_resources) | |
| 229 | end | ||||
| c7f42a91 » | ianwhite | 2008-04-27 | 230 | end | |
| 231 | |||||
| 232 | # specing some branching BC code | ||||
| 233 | # find_filter dissapeared from edge, but we want to support it for 2.0-stable | ||||
| 234 | describe "ResourcesController.load_enclosing_resources_filter_exists?" do | ||||
| 235 | before do | ||||
| 236 | @klass = Class.new(ActionController::Base) | ||||
| 237 | end | ||||
| 238 | |||||
| 239 | describe "when :find_filter defined" do | ||||
| 240 | before do | ||||
| 241 | class<<@klass | ||||
| 242 | def find_filter; end | ||||
| 243 | end | ||||
| 244 | end | ||||
| 245 | |||||
| 246 | it "should call :find_filter with :load_enclosing_resources" do | ||||
| 247 | @klass.should_receive(:find_filter).with(:load_enclosing_resources) | ||||
| 248 | @klass.send(:load_enclosing_resources_filter_exists?) | ||||
| 249 | end | ||||
| 250 | end | ||||
| 251 | |||||
| 252 | describe "when :find_filter not defined" do | ||||
| 253 | before do | ||||
| 254 | class<<@klass | ||||
| 255 | undef_method(:find_filter) rescue nil | ||||
| 256 | end | ||||
| 257 | end | ||||
| 258 | |||||
| 259 | it "should call :filter_chain" do | ||||
| 260 | @klass.should_receive(:filter_chain).and_return([]) | ||||
| 261 | @klass.send(:load_enclosing_resources_filter_exists?) | ||||
| 262 | end | ||||
| 263 | end | ||||
| 264 | end | ||||








