Class: QTest::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/qtest/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



34
35
36
37
38
39
40
# 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

Class Method Details

.find_by(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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) ⇒ Object



24
25
26
27
28
29
30
31
# 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

Instance Method Details

#all(type, opts = {}) ⇒ Object



42
43
44
45
46
47
# 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 = {}) ⇒ Object



54
55
56
57
# File 'lib/qtest/base.rb', line 54

def create(type, opts = {})
  attributes = client.create(type, opts)
  to_type(type, attributes, opts)
end

#move(opts = {}) ⇒ Object



59
60
61
62
# 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 = {}) ⇒ Object



49
50
51
52
# File 'lib/qtest/base.rb', line 49

def unique(type, opts = {})
  attributes = client.unique(type, opts)
  to_type(type, attributes, opts)
end