sneaky-save 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +175 -0
- data/README.rdoc +31 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/sneaky_save.rb +64 -0
- data/sneaky-save.gemspec +40 -0
- data/spec/fixtures.rb +21 -0
- data/spec/lib/sneaky_save_spec.rb +69 -0
- data/spec/spec_helper.rb +9 -0
- metadata +127 -0
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Packed ge
|
2
|
+
*.gem
|
3
|
+
|
4
|
+
# RubyMine metadata
|
5
|
+
.idea
|
6
|
+
|
7
|
+
# test database
|
8
|
+
db
|
9
|
+
|
10
|
+
# rcov generated
|
11
|
+
coverage
|
12
|
+
|
13
|
+
# rdoc generated
|
14
|
+
rdoc
|
15
|
+
|
16
|
+
# yard generated
|
17
|
+
doc
|
18
|
+
.yardoc
|
19
|
+
|
20
|
+
# bundler
|
21
|
+
.bundle
|
22
|
+
|
23
|
+
# jeweler generated
|
24
|
+
pkg
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.0.9)
|
5
|
+
activesupport (= 3.0.9)
|
6
|
+
builder (~> 2.1.2)
|
7
|
+
i18n (~> 0.5.0)
|
8
|
+
activerecord (3.0.9)
|
9
|
+
activemodel (= 3.0.9)
|
10
|
+
activesupport (= 3.0.9)
|
11
|
+
arel (~> 2.0.10)
|
12
|
+
tzinfo (~> 0.3.23)
|
13
|
+
activesupport (3.0.9)
|
14
|
+
arel (2.0.10)
|
15
|
+
builder (2.1.2)
|
16
|
+
diff-lcs (1.1.3)
|
17
|
+
git (1.2.5)
|
18
|
+
i18n (0.5.0)
|
19
|
+
jeweler (1.6.2)
|
20
|
+
bundler (~> 1.0)
|
21
|
+
git (>= 1.2.5)
|
22
|
+
rake
|
23
|
+
rake (0.9.2)
|
24
|
+
rcov (0.9.10)
|
25
|
+
rspec (2.6.0)
|
26
|
+
rspec-core (~> 2.6.0)
|
27
|
+
rspec-expectations (~> 2.6.0)
|
28
|
+
rspec-mocks (~> 2.6.0)
|
29
|
+
rspec-core (2.6.4)
|
30
|
+
rspec-expectations (2.6.0)
|
31
|
+
diff-lcs (~> 1.1.2)
|
32
|
+
rspec-mocks (2.6.0)
|
33
|
+
sqlite3 (1.3.4)
|
34
|
+
sqlite3-ruby (1.3.3)
|
35
|
+
sqlite3 (>= 1.3.3)
|
36
|
+
tzinfo (0.3.29)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
activerecord
|
43
|
+
bundler (~> 1.0.0)
|
44
|
+
jeweler (~> 1.6.2)
|
45
|
+
rcov
|
46
|
+
rspec
|
47
|
+
sqlite3-ruby
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
Copyright (c) 2011 PartyEarth LLC
|
2
|
+
|
3
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
4
|
+
Version 3, 29 June 2007
|
5
|
+
|
6
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
7
|
+
Everyone is permitted to copy and distribute verbatim copies
|
8
|
+
of this license document, but changing it is not allowed.
|
9
|
+
|
10
|
+
|
11
|
+
This version of the GNU Lesser General Public License incorporates
|
12
|
+
the terms and conditions of version 3 of the GNU General Public
|
13
|
+
License, supplemented by the additional permissions listed below.
|
14
|
+
|
15
|
+
0. Additional Definitions.
|
16
|
+
|
17
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
18
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
19
|
+
General Public License.
|
20
|
+
|
21
|
+
"The Library" refers to a covered work governed by this License,
|
22
|
+
other than an Application or a Combined Work as defined below.
|
23
|
+
|
24
|
+
An "Application" is any work that makes use of an interface provided
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
27
|
+
of using an interface provided by the Library.
|
28
|
+
|
29
|
+
A "Combined Work" is a work produced by combining or linking an
|
30
|
+
Application with the Library. The particular version of the Library
|
31
|
+
with which the Combined Work was made is also called the "Linked
|
32
|
+
Version".
|
33
|
+
|
34
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
37
|
+
based on the Application, and not on the Linked Version.
|
38
|
+
|
39
|
+
The "Corresponding Application Code" for a Combined Work means the
|
40
|
+
object code and/or source code for the Application, including any data
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
43
|
+
|
44
|
+
1. Exception to Section 3 of the GNU GPL.
|
45
|
+
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
48
|
+
|
49
|
+
2. Conveying Modified Versions.
|
50
|
+
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
53
|
+
that uses the facility (other than as an argument passed when the
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
55
|
+
version:
|
56
|
+
|
57
|
+
a) under this License, provided that you make a good faith effort to
|
58
|
+
ensure that, in the event an Application does not supply the
|
59
|
+
function or data, the facility still operates, and performs
|
60
|
+
whatever part of its purpose remains meaningful, or
|
61
|
+
|
62
|
+
b) under the GNU GPL, with none of the additional permissions of
|
63
|
+
this License applicable to that copy.
|
64
|
+
|
65
|
+
3. Object Code Incorporating Material from Library Header Files.
|
66
|
+
|
67
|
+
The object code form of an Application may incorporate material from
|
68
|
+
a header file that is part of the Library. You may convey such object
|
69
|
+
code under terms of your choice, provided that, if the incorporated
|
70
|
+
material is not limited to numerical parameters, data structure
|
71
|
+
layouts and accessors, or small macros, inline functions and templates
|
72
|
+
(ten or fewer lines in length), you do both of the following:
|
73
|
+
|
74
|
+
a) Give prominent notice with each copy of the object code that the
|
75
|
+
Library is used in it and that the Library and its use are
|
76
|
+
covered by this License.
|
77
|
+
|
78
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
79
|
+
document.
|
80
|
+
|
81
|
+
4. Combined Works.
|
82
|
+
|
83
|
+
You may convey a Combined Work under terms of your choice that,
|
84
|
+
taken together, effectively do not restrict modification of the
|
85
|
+
portions of the Library contained in the Combined Work and reverse
|
86
|
+
engineering for debugging such modifications, if you also do each of
|
87
|
+
the following:
|
88
|
+
|
89
|
+
a) Give prominent notice with each copy of the Combined Work that
|
90
|
+
the Library is used in it and that the Library and its use are
|
91
|
+
covered by this License.
|
92
|
+
|
93
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
94
|
+
document.
|
95
|
+
|
96
|
+
c) For a Combined Work that displays copyright notices during
|
97
|
+
execution, include the copyright notice for the Library among
|
98
|
+
these notices, as well as a reference directing the user to the
|
99
|
+
copies of the GNU GPL and this license document.
|
100
|
+
|
101
|
+
d) Do one of the following:
|
102
|
+
|
103
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
104
|
+
License, and the Corresponding Application Code in a form
|
105
|
+
suitable for, and under terms that permit, the user to
|
106
|
+
recombine or relink the Application with a modified version of
|
107
|
+
the Linked Version to produce a modified Combined Work, in the
|
108
|
+
manner specified by section 6 of the GNU GPL for conveying
|
109
|
+
Corresponding Source.
|
110
|
+
|
111
|
+
1) Use a suitable shared library mechanism for linking with the
|
112
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
113
|
+
a copy of the Library already present on the user's computer
|
114
|
+
system, and (b) will operate properly with a modified version
|
115
|
+
of the Library that is interface-compatible with the Linked
|
116
|
+
Version.
|
117
|
+
|
118
|
+
e) Provide Installation Information, but only if you would otherwise
|
119
|
+
be required to provide such information under section 6 of the
|
120
|
+
GNU GPL, and only to the extent that such information is
|
121
|
+
necessary to install and execute a modified version of the
|
122
|
+
Combined Work produced by recombining or relinking the
|
123
|
+
Application with a modified version of the Linked Version. (If
|
124
|
+
you use option 4d0, the Installation Information must accompany
|
125
|
+
the Minimal Corresponding Source and Corresponding Application
|
126
|
+
Code. If you use option 4d1, you must provide the Installation
|
127
|
+
Information in the manner specified by section 6 of the GNU GPL
|
128
|
+
for conveying Corresponding Source.)
|
129
|
+
|
130
|
+
5. Combined Libraries.
|
131
|
+
|
132
|
+
You may place library facilities that are a work based on the
|
133
|
+
Library side by side in a single library together with other library
|
134
|
+
facilities that are not Applications and are not covered by this
|
135
|
+
License, and convey such a combined library under terms of your
|
136
|
+
choice, if you do both of the following:
|
137
|
+
|
138
|
+
a) Accompany the combined library with a copy of the same work based
|
139
|
+
on the Library, uncombined with any other library facilities,
|
140
|
+
conveyed under the terms of this License.
|
141
|
+
|
142
|
+
b) Give prominent notice with the combined library that part of it
|
143
|
+
is a work based on the Library, and explaining where to find the
|
144
|
+
accompanying uncombined form of the same work.
|
145
|
+
|
146
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
147
|
+
|
148
|
+
The Free Software Foundation may publish revised and/or new versions
|
149
|
+
of the GNU Lesser General Public License from time to time. Such new
|
150
|
+
versions will be similar in spirit to the present version, but may
|
151
|
+
differ in detail to address new problems or concerns.
|
152
|
+
|
153
|
+
Each version is given a distinguishing version number. If the
|
154
|
+
Library as you received it specifies that a certain numbered version
|
155
|
+
of the GNU Lesser General Public License "or any later version"
|
156
|
+
applies to it, you have the option of following the terms and
|
157
|
+
conditions either of that published version or of any later version
|
158
|
+
published by the Free Software Foundation. If the Library as you
|
159
|
+
received it does not specify a version number of the GNU Lesser
|
160
|
+
General Public License, you may choose any version of the GNU Lesser
|
161
|
+
General Public License ever published by the Free Software Foundation.
|
162
|
+
|
163
|
+
If the Library as you received it specifies that a proxy can decide
|
164
|
+
whether future versions of the GNU Lesser General Public License shall
|
165
|
+
apply, that proxy's public statement of acceptance of any version is
|
166
|
+
permanent authorization for you to choose that version for the
|
167
|
+
Library.
|
168
|
+
|
169
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
170
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
171
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
172
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
173
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
174
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
175
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= sneaky-save
|
2
|
+
|
3
|
+
ActiveRecord extension. Allows to save record without calling callbacks and validations.
|
4
|
+
|
5
|
+
== Installing
|
6
|
+
# gem install sneaky-save
|
7
|
+
|
8
|
+
== Using
|
9
|
+
# Update
|
10
|
+
@existed_record.sneaky_save
|
11
|
+
|
12
|
+
# Insert
|
13
|
+
Model.new.sneaky_save
|
14
|
+
|
15
|
+
== Running specs
|
16
|
+
* Clone the repo
|
17
|
+
* run `bundle exec rake spec`
|
18
|
+
|
19
|
+
== Contributing to sneaky-save
|
20
|
+
|
21
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
22
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
23
|
+
* Fork the project
|
24
|
+
* Start a feature/bugfix branch
|
25
|
+
* Commit and push until you are happy with your contribution
|
26
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
27
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
28
|
+
|
29
|
+
== Copyright
|
30
|
+
|
31
|
+
Copyright (c) 2011 PartyEarth LLC. See LICENSE.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
ENV['BUNDLE_GEMFILE'] = 'Gemfile'
|
4
|
+
|
5
|
+
gem_root = File.expand_path(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'bundler'
|
9
|
+
require 'rake'
|
10
|
+
require 'jeweler'
|
11
|
+
require 'rake'
|
12
|
+
require 'rake/testtask'
|
13
|
+
require 'rspec'
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
|
16
|
+
begin
|
17
|
+
Bundler.setup(:default, :development)
|
18
|
+
rescue Bundler::BundlerError => e
|
19
|
+
$stderr.puts e.message
|
20
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
21
|
+
exit e.status_code
|
22
|
+
end
|
23
|
+
|
24
|
+
Jeweler::Tasks.new do |gem|
|
25
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
26
|
+
gem.name = "sneaky-save"
|
27
|
+
gem.homepage = "http://github.com/partyearth/sneaky-save"
|
28
|
+
gem.license = "MIT"
|
29
|
+
gem.summary = %Q{Kevin, please add summary.}
|
30
|
+
gem.description = %Q{Longer description of our gem}
|
31
|
+
gem.email = "kgoslar@partyearth.ru"
|
32
|
+
gem.authors = ["Sergei Zinin", "Kevin Goslar"]
|
33
|
+
gem.files = Dir.glob('lib/**/*.rb')
|
34
|
+
# dependencies defined in Gemfile
|
35
|
+
end
|
36
|
+
Jeweler::RubygemsDotOrgTasks.new
|
37
|
+
|
38
|
+
task :default => :spec
|
39
|
+
|
40
|
+
desc "Run the test suite"
|
41
|
+
task :spec => ['spec:setup', 'spec:lib', 'spec:cleanup']
|
42
|
+
|
43
|
+
namespace :spec do
|
44
|
+
desc "Setup the test environment"
|
45
|
+
task :setup do
|
46
|
+
system "cd #{gem_root} && bundle install && mkdir db"
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Cleanup the test environment"
|
50
|
+
task :cleanup do
|
51
|
+
FileUtils.rm_rf "#{gem_root}/db"
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "Test the SneakySave lib"
|
55
|
+
RSpec::Core::RakeTask.new(:lib) do |task|
|
56
|
+
task.pattern = gem_root + '/spec/lib/**/*_spec.rb'
|
57
|
+
end
|
58
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/sneaky_save.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2011 {PartyEarth LLC}[http://partyearth.com]
|
3
|
+
# mailto:kgoslar@partyearth.com
|
4
|
+
#++
|
5
|
+
module SneakySave
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
|
10
|
+
# Saves record without running callbacks/validations.
|
11
|
+
# Returns true if any record is changed.
|
12
|
+
#
|
13
|
+
# @note - Does not reload updated record by default.
|
14
|
+
# - Does not save associated collections.
|
15
|
+
# - Saves only belongs_to relations.
|
16
|
+
#
|
17
|
+
# @return [false, true]
|
18
|
+
def sneaky_save
|
19
|
+
begin
|
20
|
+
new_record? ? sneaky_create : sneaky_update
|
21
|
+
rescue ActiveRecord::StatementInvalid
|
22
|
+
false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
# Makes INSERT query in database without running any callbacks.
|
29
|
+
#
|
30
|
+
# @return [false, true]
|
31
|
+
def sneaky_create
|
32
|
+
if self.id.nil? && connection.prefetch_primary_key?(self.class.table_name)
|
33
|
+
self.id = connection.next_sequence_value(self.class.sequence_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
attributes_values = send :arel_attributes_values
|
37
|
+
|
38
|
+
new_id = if attributes_values.empty?
|
39
|
+
self.class.unscoped.insert connection.empty_insert_statement_value
|
40
|
+
else
|
41
|
+
self.class.unscoped.insert attributes_values
|
42
|
+
end
|
43
|
+
|
44
|
+
@new_record = false
|
45
|
+
!!(self.id ||= new_id)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Makes update query without running callbacks.
|
49
|
+
#
|
50
|
+
# @return [false, true]
|
51
|
+
def sneaky_update
|
52
|
+
|
53
|
+
# Handle no changes.
|
54
|
+
return true unless changes.any?
|
55
|
+
|
56
|
+
# Here we have changes --> save them.
|
57
|
+
pk = self.class.primary_key
|
58
|
+
original_id = changed_attributes.has_key?(pk) ? changes[pk].first : send(pk)
|
59
|
+
!self.class.update_all(attributes, pk => original_id).zero?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
ActiveRecord::Base.send :include, SneakySave
|
data/sneaky-save.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{sneaky-save}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Sergei Zinin", "Kevin Goslar"]
|
9
|
+
s.date = %q{2011-10-17}
|
10
|
+
s.description = %q{ActiveRecord extension. Allows to save record without calling callbacks and validations.}
|
11
|
+
s.email = %q{kgoslar@partyearth.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"LICENSE.txt",
|
14
|
+
"README.rdoc"
|
15
|
+
]
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.homepage = %q{http://github.com/partyearth/sneaky-save}
|
18
|
+
s.licenses = ["MIT"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubygems_version = %q{1.6.2}
|
21
|
+
s.summary = %q{Allows to save record without calling callbacks and validations.}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 2.3.2"])
|
28
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
29
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.2"])
|
32
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
33
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
34
|
+
end
|
35
|
+
else
|
36
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.2"])
|
37
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
38
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
39
|
+
end
|
40
|
+
end
|
data/spec/fixtures.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class TestMigration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
self.down
|
4
|
+
create_table(:fakes) { |t| t.string :name }
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
drop_table :fakes if ActiveRecord::Base.connection.tables.include? :fakes
|
9
|
+
end
|
10
|
+
end
|
11
|
+
TestMigration.up
|
12
|
+
|
13
|
+
class Fake < ActiveRecord::Base
|
14
|
+
validates_presence_of :name
|
15
|
+
|
16
|
+
before_save :before_save_callback
|
17
|
+
|
18
|
+
def before_save_callback
|
19
|
+
puts "BEFORE SAVE CALLED"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures'
|
3
|
+
|
4
|
+
describe SneakySave do
|
5
|
+
after :each do
|
6
|
+
subject.sneaky_save.should be_true
|
7
|
+
end
|
8
|
+
|
9
|
+
context "new record" do
|
10
|
+
subject { Fake.new }
|
11
|
+
|
12
|
+
it("returns true if everything is good") {}
|
13
|
+
|
14
|
+
it "does insert of the new record" do
|
15
|
+
subject.should_receive(:sneaky_create).once.and_return true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "stores attributes in database" do
|
19
|
+
subject.name = "test"
|
20
|
+
subject.sneaky_save
|
21
|
+
subject.reload
|
22
|
+
subject.name.should == "test"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "does not call any callback" do
|
26
|
+
Fake.any_instance.should_not_receive :before_save_callback
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not call validations" do
|
30
|
+
Fake.any_instance.should_not_receive :valid?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "existing record" do
|
35
|
+
subject { Fake.create :name => "test" }
|
36
|
+
|
37
|
+
context "record is not changed" do
|
38
|
+
it "does nothing" do
|
39
|
+
Fake.should_not_receive(:update_all)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "record is changed" do
|
44
|
+
after :each do
|
45
|
+
subject.name = 'new name'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "updates attributes" do
|
49
|
+
subject.should be_valid
|
50
|
+
subject.should_receive(:sneaky_update).once.and_return true
|
51
|
+
end
|
52
|
+
|
53
|
+
it "stores attributes in database" do
|
54
|
+
subject.name = "new name"
|
55
|
+
subject.sneaky_save.should be_true
|
56
|
+
subject.reload
|
57
|
+
subject.name.should == "new name"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "does not call any callback" do
|
61
|
+
subject.should_not_receive :before_save_callback
|
62
|
+
end
|
63
|
+
|
64
|
+
it "does not call validations" do
|
65
|
+
subject.should_not_receive :valid?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "logger"
|
3
|
+
require "rspec"
|
4
|
+
require "sneaky_save"
|
5
|
+
|
6
|
+
RSpec.configure { |config| config.mock_with :rspec }
|
7
|
+
|
8
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "db/sqlite3.test.db")
|
9
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sneaky-save
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sergei Zinin
|
14
|
+
- Kevin Goslar
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-10-17 00:00:00 +08:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: activerecord
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 7
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
- 2
|
35
|
+
version: 2.3.2
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 23
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
- 0
|
51
|
+
version: 1.0.0
|
52
|
+
type: :development
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: jeweler
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 11
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 6
|
66
|
+
- 2
|
67
|
+
version: 1.6.2
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id003
|
70
|
+
description: ActiveRecord extension. Allows to save record without calling callbacks and validations.
|
71
|
+
email: kgoslar@partyearth.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files:
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.rdoc
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.rdoc
|
85
|
+
- Rakefile
|
86
|
+
- VERSION
|
87
|
+
- lib/sneaky_save.rb
|
88
|
+
- sneaky-save.gemspec
|
89
|
+
- spec/fixtures.rb
|
90
|
+
- spec/lib/sneaky_save_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://github.com/partyearth/sneaky-save
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.5.0
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: Allows to save record without calling callbacks and validations.
|
126
|
+
test_files: []
|
127
|
+
|