Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_extensions_plugins / plugins / scenarios / spec / .svn / text-base / scenarios_spec.rb.svn-base
blob0792227ed4868af860f06304747fdae29bd763fd
1 require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
3 describe "Scenario loading" do
4   it "should load from configured directories" do
5     Scenario.load(:empty)
6     EmptyScenario
7   end
8   
9   it "should raise Scenario::NameError when the scenario does not exist" do
10     lambda { Scenario.load(:whatcha_talkin_bout) }.should raise_error(Scenario::NameError)
11   end
12   
13   it "should allow us to add helper methods through the helpers class method" do
14     klass = :empty.to_scenario
15     klass.helpers do
16       def hello
17         "Hello World"
18       end
19     end
20     klass.new.methods.should include('hello')
21   end
22   
23   it "should load the scenarios only once per test class/example group, then unload at the end, even on exception of any test" do
24     tracking_scenario = Class.new((:things).to_scenario) do
25       cattr_accessor :instance
26       def initialize(*args)
27         raise "Should only be created once" if self.class.instance
28         self.class.instance = super(*args)
29       end
30     end
31     
32     test_case = Class.new(Test::Unit::TestCase) do
33       scenario tracking_scenario
34       def test_something; end
35       def test_bad_stuff
36         # raise "bad stuff"
37       end
38     end
39     
40     test_case.suite.run
41     
42     tracking_scenario.instance.should be_unloaded
43   end
44   
45   it "should provide a built-in scenario named :blank which clears all tables found in schema.rb" do
46     Scenario.load(:blank)
47     BlankScenario
48   end
49 end
51 describe Scenarios::TableMethods do
52   scenario :things
53   
54   it "should understand namespaced models" do
55     create_record "ModelModule::Model", :raking, :name => "Raking", :description => "Moving leaves around"
56     models(:raking).should_not be_nil
57   end
58   
59   it "should include record creation methods" do
60     create_record(:thing, :three, :name => "Three")
61     things(:three).name.should == "Three"
62   end
63   
64   it "should include other example helper methods" do
65     create_thing("The Thing")
66     things(:the_thing).name.should == "The Thing"
67   end
68   
69   describe "for retrieving objects" do
70     it "should have a pluralized name" do
71       should respond_to("things")
72       should_not respond_to("thing")
73     end
74     
75     it "should answer a single object given a single name" do
76       things(:one).should be_kind_of(Thing)
77       things("one").should be_kind_of(Thing)
78       things(:two).name.should == "two"
79     end
80     
81     it "should answer an array of objects given multiple names" do
82       things(:one, :two).should be_kind_of(Array)
83       things(:one, :two).should eql([things(:one), things(:two)])
84     end
85     
86     it "should just return the argument if an AR instance is given" do
87       thing = things(:one)
88       things(thing).should eql(thing)
89     end
90   end
91   
92   describe "for retrieving ids" do
93     it "should have a singular name" do
94       should respond_to("thing_id")
95       should_not respond_to("thing_ids")
96       should_not respond_to("things_id")
97     end
98     
99     it "should answer a single id given a single name" do
100       thing_id(:one).should be_kind_of(Fixnum)
101       thing_id("one").should be_kind_of(Fixnum)
102     end
103     
104     it "should answer an array of ids given multiple names" do
105       thing_id(:one, :two).should be_kind_of(Array)
106       thing_id(:one, :two).should eql([thing_id(:one), thing_id(:two)])
107       thing_id("one", "two").should eql([thing_id(:one), thing_id(:two)])
108     end
109     
110     it "should answer the id of the argument if an AR instance id given" do
111       thing = things(:one)
112       thing_id(thing).should == thing.id
113     end
114   end
117 describe "it uses people and things scenarios", :shared => true do
118   it "should have reader helper methods for each used scenario" do
119     should respond_to(:things)
120     should respond_to(:people)
121   end
122   
123   it "should allow us to use helper methods from each scenario inside an example" do
124     should respond_to(:create_thing)
125     should respond_to(:create_person)
126   end
129 describe "A composite scenario" do
130   scenario :composite
131   
132   it_should_behave_like "it uses people and things scenarios"
133   
134   it "should allow us to use helper methods scenario" do
135     should respond_to(:method_from_composite_scenario)
136   end
139 describe "Multiple scenarios" do
140   scenario :things, :people
141   
142   it_should_behave_like "it uses people and things scenarios"
145 describe "A complex composite scenario" do
146   scenario :complex_composite
147   
148   it_should_behave_like "it uses people and things scenarios"
149   
150   it "should have correct reader helper methods" do
151     should respond_to(:places)
152   end
153   
154   it "should allow us to use correct helper methods" do
155     should respond_to(:create_place)
156   end
159 describe "Overlapping scenarios" do
160   scenario :composite, :things, :people
161   
162   it "should not cause scenarios to be loaded twice" do
163     Person.find_all_by_first_name("John").size.should == 1
164   end
167 describe "create_record table method" do
168   scenario :empty
169   
170   it "should automatically set timestamps" do
171     create_record :note, :first, :content => "first note"
172     note = notes(:first)
173     note.created_at.should be_instance_of(Time)
174   end
177 describe "create_model table method" do
178   scenario :empty
179   
180   it "should support symbolic names" do
181     thing = create_model Thing, :mything, :name => "My Thing", :description => "For testing"
182     things(:mything).should == thing
183   end
184   
185   it "should blast any table touched as a side effect of creating a model (callbacks, observers, etc.)" do
186     create_model SideEffectyThing
187     blasted_tables.should include(Thing.table_name)
188   end