1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
require File.dirname(__FILE__) + '/../test_helper'
describe "A person with no privileges" do
use_controller StorySectionsController
before(:each) do
@person = person_mock
end
it "should not have access to anything" do
Story.any_instance.stubs(:person).returns(@person)
%w(show new edit create update destroy).each do |action|
get action.to_sym, :id => 1
response.should.redirect login_path
end
end
end
describe "A logged in person" do
use_controller StorySectionsController
before(:each) do
@person = person_mock
@story_section = story_section_mock
@story = story_mock
login @person
Person.stubs(:find_by_id).returns(@person)
@action = "be able to"
end
it "should #{@action} to create a text section" do
StorySection.expects(:create_specific).returns(@story_section)
@story_section.expects(:story).returns(@story)
xhr :post, :create, :section_id => 1, :story_id => 1, :clicked_type => 'text'
output.should.match /html/
end
it "should be logged out when trying to create a nonexistent section type via ajax" do
StorySection.expects(:create_specific).returns(false)
xhr :post, :create, :section_id => 1, :story_id => 1, :clicked_type => 'BadBad'
response.should.redirect home_path
session[:person].should.be.nil
end
it "should #{@action} destroy an owned section via ajax" do
StorySection.expects(:find).returns(@story_section)
@story_section.expects(:destroy).returns(true)
xhr :delete, :destroy, :id => 1
status.should.be :success
end
it "should #{@action} update existing text section via ajax" do
StorySection.expects(:find).returns(@story_section)
@story_section.expects(:is_a?).returns(false)
@story_section.expects(:update_attributes).returns(true)
xhr :put, :update, :id => 1, :story_section => {:content => 'test'}
status.should.be :success
end
it "should #{@action} update existing picture section via ajax" do
StorySection.expects(:find).returns(@story_section)
@story_section.section_pictures.expects(:reload).returns(true)
xhr :put, :update, :story_id => 1, :id => 1, :story_section => {:picture_id => 1}
status.should.be :success
end
end
|