active_mocker 1.2.4 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +0,0 @@
1
- module ActiveHash
2
-
3
- module ARApi
4
- require 'active_record/errors'
5
-
6
- module FindBy
7
-
8
- def find_by(options = {})
9
- send(:where, options).first
10
- end
11
-
12
- def find_by!(options={})
13
- result = find_by(options)
14
- raise ActiveRecord::RecordNotFound if result.blank?
15
- result
16
- end
17
-
18
- def where(options)
19
- return @records if options.nil?
20
- (@records || []).select do |record|
21
- options.all? do |col, match|
22
- record.send(col) == match
23
- end
24
- end
25
- end
26
-
27
- end
28
-
29
- end
30
-
31
- end
@@ -1,18 +0,0 @@
1
- module ActiveHash
2
-
3
- module ARApi
4
-
5
- module Update
6
-
7
- def update(options={})
8
- options.each do |method, value|
9
- send("#{method}=", value)
10
- end
11
-
12
- end
13
-
14
- end
15
-
16
- end
17
-
18
- end
@@ -1,41 +0,0 @@
1
- module ActiveMocker
2
-
3
- class CollectionAssociation
4
-
5
- include Enumerable
6
-
7
- def initialize(collection=[])
8
- @association = [*collection]
9
- end
10
-
11
- def <<(*records)
12
- association.concat(records.flatten)
13
- end
14
-
15
- delegate :any?, :empty?, :length, :size, :count, :uniq, :replace, :first, :last, :concat, :include?, :push, :clear, :take, to: :association
16
- alias distinct uniq
17
-
18
- def sum(attribute=nil)
19
- values = association.map { |obj| obj.send(attribute) }
20
- values.inject { |sum, n| sum + n }
21
- end
22
-
23
- def ==(other_ary)
24
- association == other_ary
25
- end
26
-
27
- def each(&block)
28
- association.each do |item|
29
- block.call(item)
30
- end
31
- end
32
-
33
- def to_a
34
- @association
35
- end
36
-
37
- private
38
- attr_accessor :association
39
-
40
- end
41
- end