json_api_client_mock 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f89a3d8750fb2b9a6b2776751b262beb69ce585b
4
- data.tar.gz: a0c875e9b5c69a37013d7fd1336cf3ff09546efc
3
+ metadata.gz: e62e74f6a4163d43ba75e943c68aff457a67c8ef
4
+ data.tar.gz: 7f3ebc0fa5d282d3d368d84af9b4bd8dbe9eb301
5
5
  SHA512:
6
- metadata.gz: ff105c8ed2e4810f855dba4542111248d7ce79d3864980737b09bd8f968273aed0855e1cee3ecdd327f24505f5cdf6aceb1a1e6937a03c913c47671e39fa4b9c
7
- data.tar.gz: 6d488de5f0d1c3a71bdcec8e2e5f809f6bdb80f40a7cc1b6c73e0713d07ead7c0a9618ffa1bf2b624a797955fd68a8940b75b0fd95cdb1b715ff5fa0d5749ab7
6
+ metadata.gz: 4146df344d2cc37a798ff3e5cfdc187a1ca3253eeeb6e6046ccf04e7618f2374767fc9249abd43e7ab826e522aeb89ae359567364385a22ef6adb3b7ba6f0a9e
7
+ data.tar.gz: ddde9037bc917ec35a29bab0b45f951cb8552851e568bdfce5158141d24f9d00407155b03649a001876b3746702c96c61afb83c4cad0d827068d44778db7a222
@@ -16,8 +16,8 @@ module JsonApiClientMock
16
16
  query.klass.table_name => results[:results]
17
17
  })
18
18
  else
19
- raise MissingMock, "no test results set for #{query.klass.name} with conditions: #{query.params.inspect}"
20
- end
19
+ raise MissingMock, missing_message(query)
20
+ end
21
21
  end
22
22
 
23
23
  def set_test_results(klass, results, conditions = nil)
@@ -31,10 +31,18 @@ module JsonApiClientMock
31
31
 
32
32
  protected
33
33
 
34
+ def class_mocks(query)
35
+ self.class.mocks.fetch(query.klass.name, [])
36
+ end
37
+
34
38
  def find_test_results(query)
35
- class_mocks = self.class.mocks.fetch(query.klass.name, [])
36
- class_mocks.detect{|mock| mock[:conditions] == query.params} ||
37
- class_mocks.detect{|mock| mock[:conditions].nil?}
39
+ class_mocks(query).detect{|mock| mock[:conditions] == query.params} ||
40
+ class_mocks(query).detect{|mock| mock[:conditions].nil?}
41
+ end
42
+
43
+ def missing_message(query)
44
+ ["no test results set for #{query.klass.name} with conditions: #{query.params.pretty_inspect}",
45
+ "mocks conditions available: #{class_mocks(query).map {|m| m[:conditions]}.pretty_inspect}"].join("\n\n")
38
46
  end
39
47
  end
40
- end
48
+ end
@@ -3,7 +3,8 @@ module JsonApiClientMock
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- self.connection_class = MockConnection
6
+ class_attribute :original_connection_class, :original_connection_object
7
+ self.disable_net_connect!
7
8
  end
8
9
 
9
10
  module ClassMethods
@@ -15,6 +16,17 @@ module JsonApiClientMock
15
16
  connection.clear_test_results
16
17
  end
17
18
 
19
+ def allow_net_connect!
20
+ self.connection_class = self.original_connection_class
21
+ self.connection_object = self.original_connection_object
22
+ end
23
+
24
+ def disable_net_connect!
25
+ self.original_connection_class = self.connection_class
26
+ self.original_connection_object = self.connection_object
27
+ self.connection_class = MockConnection
28
+ self.connection_object = nil
29
+ end
18
30
  end
19
31
  end
20
- end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module JsonApiClientMock
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -74,4 +74,37 @@ class JsonApiClientMockTest < MiniTest::Unit::TestCase
74
74
  end
75
75
  end
76
76
 
77
+ def test_allow_net_connect
78
+ BarResource.allow_net_connect!
79
+
80
+ BarResource.connection
81
+
82
+ # base still has mock connection
83
+ assert_equal JsonApiClientMock::MockConnection,
84
+ JsonApiClient::Resource.connection_class
85
+
86
+ # other connections still have mock connection
87
+ assert_equal JsonApiClientMock::MockConnection,
88
+ FooResource.connection_class
89
+
90
+ # bar has real connection
91
+ assert_equal JsonApiClient::Connection,
92
+ BarResource.connection_class
93
+
94
+ # actual connection is not a mock
95
+ assert_equal JsonApiClient::Connection,
96
+ BarResource.connection_object.class
97
+
98
+ BarResource.disable_net_connect!
99
+
100
+ BarResource.connection
101
+
102
+ # bar has mock connection again
103
+ assert_equal JsonApiClientMock::MockConnection,
104
+ BarResource.connection_class
105
+
106
+ # actual connection is a mock again
107
+ assert_equal JsonApiClientMock::MockConnection,
108
+ BarResource.connection_object.class
109
+ end
77
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_client_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.4
19
+ version: 0.3.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.4
26
+ version: 0.3.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mocha
29
29
  requirement: !ruby/object:Gem::Requirement