Updated Rails to 2.1.0
[gitorious:georgyos-clone.git] / vendor / plugins / rspec_on_rails / lib / spec / rails / example / assigns_hash_proxy.rb
1 module Spec
2   module Rails
3     module Example
4       class AssignsHashProxy #:nodoc:
5         def initialize(object)
6           @object = object
7         end
8
9         def [](ivar)
10           if assigns.include?(ivar.to_s)
11             assigns[ivar.to_s]
12           elsif assigns.include?(ivar)
13             assigns[ivar]
14           else
15             nil
16           end
17         end
18
19         def []=(ivar, val)
20           @object.instance_variable_set "@#{ivar}", val
21           assigns[ivar.to_s] = val
22         end
23
24         def delete(name)
25           assigns.delete(name.to_s)
26         end
27
28         def each(&block)
29           assigns.each &block
30         end
31
32         def has_key?(key)
33           assigns.key?(key.to_s)
34         end
35
36         protected
37         def assigns
38           @object.assigns
39         end
40       end
41     end
42   end
43 end