sixarm_ruby_active_record_mock 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/CHANGELOG.txt ADDED
@@ -0,0 +1,6 @@
1
+ CHANGELOG
2
+
3
+ 2011-04-19 1.4.2 Add <attribute>_before_type_cast
4
+ 2011-04-19 1.4.0 Add attributes via method_missing
5
+ 2011-04-18 1.3.2 Add find(nil) to return nil
6
+ 2011-04-17 1.3.0 Update for Ruby 1.9.2 and Rails 3.0.5
data/INSTALL.txt ADDED
@@ -0,0 +1,32 @@
1
+
2
+ = SixArm.com Ruby Gem Install
3
+
4
+
5
+ First-time users: add our gem certificate and source.
6
+ When you do this once, it works for all our gems.
7
+
8
+ sudo wget http://sixarm.com/sixarm.pem
9
+ sudo gem cert --add sixarm.pem
10
+ sudo gem sources --add http://sixarm.com
11
+
12
+ Install the gem with advanced options.
13
+
14
+ sudo gem install sixarm_ruby_active_record_mock --test --trust-policy HighSecurity
15
+
16
+
17
+ == Notes
18
+
19
+ Do you have any questions, comments, suggestions, or feedback?
20
+ Let us know, we're happy to help. Our email is sixarm@sixarm.com
21
+
22
+ Do you want to create your own high security gems?
23
+ Learn how at http://www.rubygems.org/read/chapter/21
24
+
25
+ To see your current gem certificate list:
26
+
27
+ sudo gem cert --list
28
+
29
+ Our cert looks like this:
30
+
31
+ /C=US/ST=California/L=San Francisco/O=SixArm/CN=sixarm.com
32
+
data/LICENSE.txt ADDED
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+
3
+ You may choose any of these licenses:
4
+
5
+ - CreativeCommons License, Non-commercial Share Alike
6
+ - LGPL, GNU Lesser General Public License
7
+ - MIT License
8
+ - Ruby License
9
+
10
+ THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ = SixArm.com » Ruby » ActiveRecord mock object for testing Rails
2
+
3
+ Author:: Joel Parker Henderson, joel@joelparkerhenderson.com
4
+ Copyright:: Copyright (c) 2006-2011 Joel Parker Henderson
5
+ License:: See LICENSE.txt file
6
+
7
+ A simple mock object that provides the ActiveRecord method
8
+ signatures read_attribute(key) and write_attribute(key,val),
9
+ and simple record finder signatures find(id) and find(:all).
10
+
11
+
12
+ This provides some of the ActiveRecord method signatures we use:
13
+ - read_attribute(key)
14
+ - write_attribute(key,val)
15
+ - find(id)
16
+ - find(:all)
17
+
18
+ Example:
19
+ mock = ActiveRecordMock.new
20
+ mock.write_attribute('foo','bar')
21
+ mock.read_attribute('foo') => 'bar'
22
+
23
+ Example of initialize with attributes:
24
+ mock = ActiveRecordMock.new(:foo => 'bar', :goo => 'car', :hoo => 'dar')
25
+ mock.read_attribute(:foo') => 'bar'
26
+ mock.read_attribute(:goo') => 'car'
27
+ mock.read_attribute(:hoo') => 'dar'
28
+
29
+ Example of creating mock users:
30
+ anne = ActiveRecordMock.new(:id => 123, :name => 'Anne')
31
+ beth = ActiveRecordMock.new(:id => 456, :name => 'Beth')
32
+ cate = ActiveRecordMock.new(:id => 789, :name => 'Cate')
33
+
34
+ Example of mock finder creation:
35
+ ActiveRecordMock.find=[anne,beth,cate]
36
+
37
+ Example of mock finder retrieval of records by id:
38
+ ActiveRecordMock.find(123) => anne
39
+ ActiveRecordMock.find(456) => beth
40
+ ActiveRecordMock.find(789) => cate
41
+
42
+ Example of mock finder retrieval of all records:
43
+ ActiveRecordMock.find(:all) => [anne,beth,cate]
44
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib' << 'test'
7
+ t.pattern = 'test/*.rb'
8
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.4.2
@@ -0,0 +1,50 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README.rdoc
4
+ =end
5
+
6
+ class ActiveRecordMock
7
+
8
+ @@find=[]
9
+
10
+ def initialize(ops={})
11
+ @attributes=ops
12
+ @@find << self
13
+ end
14
+
15
+ def read_attribute(k)
16
+ @attributes[k]
17
+ end
18
+
19
+ def write_attribute(k,v)
20
+ @attributes[k]=v
21
+ end
22
+
23
+ def self.find(id,*ops)
24
+ case id
25
+ when nil
26
+ nil
27
+ when :all
28
+ @@find
29
+ else
30
+ @@find.each{|x| if x.read_attribute(:id)==id then return x end } or nil
31
+ end
32
+ end
33
+
34
+ def self.find=(records)
35
+ @@find=records
36
+ end
37
+
38
+ def method_missing(m, *args, &block)
39
+ if m=~/=$/
40
+ write_attribute(m.to_s.sub(/=$/,'').to_sym, *args)
41
+ else
42
+ if m=~/_before_type_cast$/
43
+ read_attribute($`.to_sym)
44
+ else
45
+ read_attribute(m)
46
+ end
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,91 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test/unit'
3
+ require 'sixarm_ruby_active_record_mock'
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+
7
+ class Testing < Test::Unit::TestCase
8
+
9
+ def test_instantiation
10
+ mock1 = ActiveRecordMock.new
11
+ mock2 = ActiveRecordMock.new
12
+ assert_not_same(mock1,mock2,"mock1,mock2")
13
+ end
14
+
15
+ def test_attribute_assignment
16
+ mock = ActiveRecordMock.new
17
+ key='foo'
18
+ val='bar'
19
+ mock.write_attribute(key,val)
20
+ out=mock.read_attribute(key)
21
+ assert_equal(val,out,"mock key:#{key} val:#{val} out:#{out}")
22
+ end
23
+
24
+ def test_attribute_independence
25
+ mock = ActiveRecordMock.new
26
+ key1='foo'
27
+ val1='bar'
28
+ key2='hello'
29
+ val2='world'
30
+ mock.write_attribute(key1,val1)
31
+ mock.write_attribute(key2,val2)
32
+ out1=mock.read_attribute(key1)
33
+ out2=mock.read_attribute(key2)
34
+ assert_equal(val1,out1,"mock key1:#{key1} val1:#{val1} out:#{out1}")
35
+ assert_equal(val2,out2,"mock key2:#{key2} val2:#{val2} out:#{out2}")
36
+ assert_not_equal(key1,key2,"key1,key2")
37
+ assert_not_equal(val1,val2,"val1,val2")
38
+ assert_not_equal(out1,out2,"out1,out2")
39
+ end
40
+
41
+ def test_initialize_attributes
42
+ mock = ActiveRecordMock.new(:foo => 'bar', :goo => 'car', :hoo => 'dar')
43
+ x = mock.read_attribute(:foo); assert_equal(x,'bar',"x:#{x},bar")
44
+ x = mock.read_attribute(:goo); assert_equal(x,'car',"x:#{x},car")
45
+ x = mock.read_attribute(:hoo); assert_equal(x,'dar',"x:#{x},dar")
46
+ end
47
+
48
+ def test_attribute_via_initializer
49
+ mock = ActiveRecordMock.new(:foo => 'bar')
50
+ assert_equal("bar", mock.foo, 'mock.foo should equal "bar"')
51
+ end
52
+
53
+ def test_attribute_via_assignment
54
+ mock = ActiveRecordMock.new()
55
+ mock.foo='bar'
56
+ assert_equal("bar", mock.foo, 'mock.foo should equal "bar"')
57
+ end
58
+
59
+ def test_attribute_before_type_cast
60
+ mock = ActiveRecordMock.new(:foo => 'bar')
61
+ assert_equal("bar", mock.foo_before_type_cast, 'mock.foo_before_type_cast should equal "bar"')
62
+ end
63
+
64
+ def test_find
65
+
66
+ anne = ActiveRecordMock.new(:id=>1, :name=>'Anne')
67
+ beth = ActiveRecordMock.new(:id=>2, :name=>'Beth')
68
+ cate = ActiveRecordMock.new(:id=>3, :name=>'Cate')
69
+
70
+ x=anne.read_attribute(:name); assert_equal(x,'Anne',"x:#{x},anne")
71
+ x=beth.read_attribute(:name); assert_equal(x,'Beth',"x:#{x},beth")
72
+ x=cate.read_attribute(:name); assert_equal(x,'Cate',"x:#{x},cate")
73
+
74
+ # Set the mock finder
75
+ all = [anne,beth,cate]
76
+ ActiveRecordMock.find=all
77
+
78
+ # Retrieve all
79
+ x = ActiveRecordMock.find(:all)
80
+ assert_equal(x,all,"find :all x:#{x}")
81
+
82
+ # Retrieve by id
83
+ x = ActiveRecordMock.find(1); assert_equal(x,anne,"find(1) x:#{x},anne")
84
+ x = ActiveRecordMock.find(2); assert_equal(x,beth,"find(2) x:#{x},beth")
85
+ x = ActiveRecordMock.find(3); assert_equal(x,cate,"find(3) x:#{x},cate")
86
+
87
+ # Retrieve by nil
88
+ x = ActiveRecordMock.find(nil); assert_nil(x,"find(nil) should be nil")
89
+ end
90
+
91
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ 9��d5�A��XѵύJf�Ѻ@U�5׏G��<��>V`5�����T�E�K��W{[�$�S�L�H-I���4R������l]�#�o�c���!a�P%�8�
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixarm_ruby_active_record_mock
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.4.2
6
+ platform: ruby
7
+ authors:
8
+ - SixArm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIDBDCCAm2gAwIBAgIJAKPwEETU5bHoMA0GCSqGSIb3DQEBBQUAMGAxCzAJBgNV
15
+ BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp
16
+ c2NvMQ8wDQYDVQQKEwZTaXhBcm0xEzARBgNVBAMTCnNpeGFybS5jb20wHhcNMTAx
17
+ MjEzMjMyNzEzWhcNMTMwOTA4MjMyNzEzWjBgMQswCQYDVQQGEwJVUzETMBEGA1UE
18
+ CBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEPMA0GA1UEChMG
19
+ U2l4QXJtMRMwEQYDVQQDEwpzaXhhcm0uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GN
20
+ ADCBiQKBgQC94mD9JDwBsunsOI0VR3CXXbOWg9cWaWciwFyJNFiM7A9I8KPLfXUw
21
+ QC4czUe5ZuG4WHvinrWhkrCK+1dWBqoEClxdF/FoKO5a+tonGCjjmfy81JmFjjyx
22
+ eTsjsHyvw+Qik9kpf9aj6+pnkNrVswgNHVea2o9yabbEiS6VSeJWoQIDAQABo4HF
23
+ MIHCMB0GA1UdDgQWBBQzPJtqmSgc53eDN7aSzDQwr9TALDCBkgYDVR0jBIGKMIGH
24
+ gBQzPJtqmSgc53eDN7aSzDQwr9TALKFkpGIwYDELMAkGA1UEBhMCVVMxEzARBgNV
25
+ BAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xDzANBgNVBAoT
26
+ BlNpeEFybTETMBEGA1UEAxMKc2l4YXJtLmNvbYIJAKPwEETU5bHoMAwGA1UdEwQF
27
+ MAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAooEexP/oPam1TP71SyuhxMb+uTrZbSQe
28
+ jVB+ExRwWadGwaNPUA56d39qwavwP+iu+3JpeonNMVvbWXF5naCX/dNFIeREHzER
29
+ ZDRQYMqru9TEMna6HD9zpcstF7vwThGovlOQ+3Y6plQ4nMzipXcZ9THqs65PIL0q
30
+ eabwpCbAopo=
31
+ -----END CERTIFICATE-----
32
+
33
+ date: 2011-04-19 00:00:00 -07:00
34
+ default_executable:
35
+ dependencies: []
36
+
37
+ description:
38
+ email: sixarm@sixarm.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gemtest
47
+ - CHANGELOG.txt
48
+ - INSTALL.txt
49
+ - LICENSE.txt
50
+ - Rakefile
51
+ - README.rdoc
52
+ - VERSION
53
+ - lib/sixarm_ruby_active_record_mock.rb
54
+ - test/sixarm_ruby_active_record_mock_test.rb
55
+ has_rdoc: true
56
+ homepage: http://sixarm.com/
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.6.2
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: "SixArm.com \xC2\xBB Ruby \xC2\xBB ActiveRecord mock object for methods read_attribute and write_attribute"
83
+ test_files:
84
+ - test/sixarm_ruby_active_record_mock_test.rb
metadata.gz.sig ADDED
Binary file