active_record_connectionless 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Marcin Nowicki <pr0d1r2@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ = active_record_connectionless
2
+
3
+ This gem provides connectionless active_record models useful for testing.
4
+
5
+ Distributed on MIT license.
6
+
7
+ == Note on Patches/Pull Requests
8
+
9
+ * Fork the project.
10
+ * Make your feature addition or bug fix.
11
+ * Add tests for it. This is important so I don't break it in a
12
+ future version unintentionally.
13
+ * Commit, do not mess with rakefile, version, or history.
14
+ (if you want to have your own version, that is fine but
15
+ bump version in a commit by itself I can ignore when I pull)
16
+ * Send me a pull request. Bonus points for topic branches.
17
+
18
+ == Copyright
19
+
20
+ Copyright (c) 2009 Marcin Nowicki <pr0d1r2@gmail.com>. See LICENSE for details.
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "active_record_connectionless"
8
+ gem.summary = %Q{connectionless active_record models}
9
+ gem.description = %Q{This gem provides connectionless active_record models useful for testing}
10
+ gem.email = "pr0d1r2@gmail.com"
11
+ gem.homepage = "http://github.com/Pr0d1r2/active_record_connectionless"
12
+ gem.authors = ["Marcin Nowicki"]
13
+ gem.add_development_dependency "rspec"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ if File.exist?('VERSION')
39
+ version = File.read('VERSION')
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "active_record_connectionless #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.2
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{active_record_connectionless}
8
+ s.version = "1.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Marcin Nowicki"]
12
+ s.date = %q{2009-09-23}
13
+ s.description = %q{This gem provides connectionless active_record models useful for testing}
14
+ s.email = %q{pr0d1r2@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "active_record_connectionless.gemspec",
27
+ "lib/active_record_connectionless.rb",
28
+ "spec/active_record_connectionless_spec.rb",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.has_rdoc = true
32
+ s.homepage = %q{http://github.com/Pr0d1r2/active_record_connectionless}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.1}
36
+ s.summary = %q{connectionless active_record models}
37
+ s.test_files = [
38
+ "spec/active_record_connectionless_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 2
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 0"])
53
+ end
54
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+
4
+ ActiveRecord::Base.class_eval do
5
+
6
+ def self.columns
7
+ @columns ||= [];
8
+ end
9
+
10
+ def self.column(name, sql_type = nil, default = nil, null = true)
11
+ columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
12
+ end
13
+
14
+ # Override the save method to prevent exceptions.
15
+ def save(validate = true)
16
+ validate ? valid? : true
17
+ end
18
+
19
+ def self.emulate_attribute(*names)
20
+ names.each do |name|
21
+ attr_accessor name
22
+ define_method("#{name}_before_type_cast") do
23
+ self.send(name)
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ class ActiveRecordConnectionless < ActiveRecord::Base
4
+ end
5
+
6
+
7
+ describe "ActiveRecordConnectionless" do
8
+
9
+ it 'should allow to make new object without exception' do
10
+ lambda {
11
+ ActiveRecordConnectionless.new
12
+ }.should_not raise_error(ActiveRecord::ConnectionNotEstablished)
13
+ end
14
+
15
+ it 'should allow to save new object without exception' do
16
+ lambda {
17
+ ActiveRecordConnectionless.new.save
18
+ }.should_not raise_error(ActiveRecord::ConnectionNotEstablished)
19
+ end
20
+
21
+ describe 'emulate_attribute' do
22
+ it 'should provide emulate_attribute method that create emulated activerecord attributes' do
23
+ ActiveRecordConnectionless.should_receive(:attr_accessor).with(:name1)
24
+ ActiveRecordConnectionless.should_receive(:define_method).with("name1_before_type_cast")
25
+ ActiveRecordConnectionless.should_receive(:attr_accessor).with(:name2)
26
+ ActiveRecordConnectionless.should_receive(:define_method).with("name2_before_type_cast")
27
+ ActiveRecordConnectionless.emulate_attribute(:name1, :name2)
28
+ end
29
+
30
+ it 'should create an method which points to original attribute' do
31
+ ActiveRecordConnectionless.emulate_attribute(:name)
32
+ active_record_connectionless = ActiveRecordConnectionless.new(:name => 'name')
33
+ active_record_connectionless.name_before_type_cast.should == 'name'
34
+ end
35
+
36
+ it 'should create methods which points to original attributes for multiple' do
37
+ ActiveRecordConnectionless.emulate_attribute(:name1, :name2)
38
+ active_record_connectionless = ActiveRecordConnectionless.new(:name1 => 'name1', :name2 => 'name2')
39
+ active_record_connectionless.name1_before_type_cast.should == 'name1'
40
+ active_record_connectionless.name2_before_type_cast.should == 'name2'
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'active_record_connectionless'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record_connectionless
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 2
9
+ version: 1.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Marcin Nowicki
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2009-09-23 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: This gem provides connectionless active_record models useful for testing
33
+ email: pr0d1r2@gmail.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - LICENSE
40
+ - README.rdoc
41
+ files:
42
+ - .document
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - active_record_connectionless.gemspec
49
+ - lib/active_record_connectionless.rb
50
+ - spec/active_record_connectionless_spec.rb
51
+ - spec/spec_helper.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/Pr0d1r2/active_record_connectionless
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.6
79
+ signing_key:
80
+ specification_version: 2
81
+ summary: connectionless active_record models
82
+ test_files:
83
+ - spec/active_record_connectionless_spec.rb
84
+ - spec/spec_helper.rb