active_mocker 1.2.4 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -11
- data/active_mocker.gemspec +1 -1
- data/lib/active_hash/ar_api.rb +23 -4
- data/lib/active_hash/init.rb +5 -1
- data/lib/active_mocker.rb +0 -1
- data/lib/active_mocker/collection/association.rb +12 -0
- data/lib/active_mocker/collection/base.rb +65 -0
- data/lib/active_mocker/collection/queries.rb +105 -0
- data/lib/active_mocker/collection/relation.rb +11 -0
- data/lib/active_mocker/mock_instance_methods.rb +3 -1
- data/lib/active_mocker/mock_requires.rb +3 -1
- data/lib/active_mocker/mock_template.erb +6 -6
- data/lib/active_mocker/version.rb +1 -1
- data/sample_app_rails_4/config/application.rb +1 -1
- data/sample_app_rails_4/db/schema.rb +1 -0
- data/sample_app_rails_4/spec/compare_mocker_and_record_spec.rb +496 -42
- data/sample_app_rails_4/spec/mocks/micropost_mock.rb +19 -10
- data/sample_app_rails_4/spec/mocks/relationship_mock.rb +8 -8
- data/sample_app_rails_4/spec/mocks/user_mock.rb +22 -22
- data/sample_app_rails_4/spec/user_mock_spec.rb +0 -1
- data/spec/lib/active_mocker/{collection_association_spec.rb → collection.rb} +4 -5
- data/spec/lib/active_mocker/generate_spec.rb +19 -30
- metadata +12 -11
- data/lib/active_hash/find_by.rb +0 -31
- data/lib/active_hash/update.rb +0 -18
- data/lib/active_mocker/collection_association.rb +0 -41
data/lib/active_hash/find_by.rb
DELETED
@@ -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
|
data/lib/active_hash/update.rb
DELETED
@@ -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
|