spec/plugin/flash_spec.rb in roda-0.9.0 vs spec/plugin/flash_spec.rb in roda-1.0.0

- old
+ new

@@ -1,12 +1,7 @@ require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__))) -begin - require 'sinatra/flash/hash' -rescue LoadError - warn "sinatra-flash not installed, skipping flash plugin test" -else describe "flash plugin" do it "flash.now[] sets flash for current page" do app(:bare) do use Rack::Session::Cookie, :secret => "1" plugin :flash @@ -54,6 +49,75 @@ b.join.should == 'b' _, h, b = req(env[h]) b.join.should == 'bb' end end + +describe "FlashHash" do + before do + @h = Roda::RodaPlugins::Flash::FlashHash.new + end + + it ".new should accept nil for empty hash" do + @h = Roda::RodaPlugins::Flash::FlashHash.new(nil) + @h.now.should == {} + @h.next.should == {} + end + + it ".new should accept a hash" do + @h = Roda::RodaPlugins::Flash::FlashHash.new(1=>2) + @h.now.should == {1=>2} + @h.next.should == {} + end + + it "#[]= assigns to next flash" do + @h[1] = 2 + @h.now.should == {} + @h.next.should == {1=>2} + end + + it "#discard removes given key from next hash" do + @h[1] = 2 + @h[nil] = 3 + @h.next.should == {1=>2, nil=>3} + @h.discard(nil) + @h.next.should == {1=>2} + @h.discard(1) + @h.next.should == {} + end + + it "#discard removes all entries from next hash with no arguments" do + @h[1] = 2 + @h[nil] = 3 + @h.next.should == {1=>2, nil=>3} + @h.discard + @h.next.should == {} + end + + it "#keep copies entry for key from current hash to next hash" do + @h.now[1] = 2 + @h.now[nil] = 3 + @h.next.should == {} + @h.keep(nil) + @h.next.should == {nil=>3} + @h.keep(1) + @h.next.should == {1=>2, nil=>3} + end + + it "#keep copies all entries from current hash to next hash" do + @h.now[1] = 2 + @h.now[nil] = 3 + @h.next.should == {} + @h.keep + @h.next.should == {1=>2, nil=>3} + end + + it "#sweep replaces current hash with next hash" do + @h[1] = 2 + @h[nil] = 3 + @h.next.should == {1=>2, nil=>3} + @h.now.should == {} + @h.sweep.should == {1=>2, nil=>3} + @h.next.should == {} + @h.now.should == {1=>2, nil=>3} + end end