class QTest::Base
Public Class Methods
find_by(opts = {})
click to toggle source
# File lib/qtest/base.rb, line 6 def find_by(opts = {}) return self.new(client.unique(self, opts)) if opts[:id] response = client.all(self, opts) return if response.empty? response.each do |object| opts.each do |opt_key, opt_value| return self.new(object) if object[opt_key] == opt_value end end if opts[:page] opts[:page] += 1 find_by(opts) end end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/qtest/base.rb, line 24 def method_missing(name, *args, &block) if name == :client raise QTest::Error, 'No QTest::Client found. Create one using QTest::Client.new first.' else super end end
new(opts = {})
click to toggle source
# File lib/qtest/base.rb, line 34 def initialize(opts = {}) opts.each do |key, value| if self.respond_to?("#{key}=") self.send(:"#{key}=", value) end end end
Public Instance Methods
all(type, opts = {})
click to toggle source
# File lib/qtest/base.rb, line 42 def all(type, opts = {}) attributes = client.all(type, opts) attributes.map do |attribute| to_type(type, attribute, opts) end end
create(type, opts = {})
click to toggle source
# File lib/qtest/base.rb, line 54 def create(type, opts = {}) attributes = client.create(type, opts) to_type(type, attributes, opts) end
move(opts = {})
click to toggle source
# File lib/qtest/base.rb, line 59 def move(opts = {}) attributes = client.move(self.class, opts) to_type(self.class, attributes, opts) end
unique(type, opts = {})
click to toggle source
# File lib/qtest/base.rb, line 49 def unique(type, opts = {}) attributes = client.unique(type, opts) to_type(type, attributes, opts) end
Private Instance Methods
to_type(type, attributes, opts = {})
click to toggle source
@api private
# File lib/qtest/base.rb, line 67 def to_type(type, attributes, opts = {}) resource = type.new(attributes) transfer_relationships(resource, opts) end
transfer_relationships(resource, opts = {})
click to toggle source
@api private
# File lib/qtest/base.rb, line 73 def transfer_relationships(resource, opts = {}) self_class = self.class.to_s.demodulize.underscore.to_sym if resource.respond_to?("#{self_class}=") resource.send("#{self_class}=", self) end opts.each_key do |key| next if key == self_class if resource.respond_to?("#{key}=") resource.send("#{key}=", self.send(key)) end end resource end