Sha256: d130eb9d0884eb439fb8d3a64a2e0d2207f6555fdd53c4c2a44c6d8f596acccf
Contents?: true
Size: 880 Bytes
Versions: 1
Compression:
Stored size: 880 Bytes
Contents
module Loquor module ResourceMock def self.extended(x) x.class_eval do def method_missing(name, *args) if name[-1] == "=" if self.class.attributes.keys.map{ |k| :"#{k}=" }.include?(name) attr = name.to_s[0..-2].to_sym @data[attr] = args[0] else raise NameError.new("undefined local variable or method '#{name}' for Resource Mock") end else super(name, *args) end end end end def attributes @attributes end def attributes=(attrs) @attributes = attrs end def sample self.new(attributes) end def find(id) self.new(attributes.merge(id: id)) end def where(*args) [ find(1), find(2) ] end def create(attrs) self.new(attrs) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
loquor-0.5.2 | lib/loquor/resource_mock.rb |