bounce 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -9
- data/Rakefile +9 -0
- data/lib/bounce/railtie.rb +13 -3
- data/lib/bounce/version.rb +1 -1
- data/test/bounce_test.rb +70 -0
- data/test/fixtures/article.rb +3 -0
- data/test/fixtures/bounce.sqlite3 +0 -0
- data/test/fixtures/schema.rb +6 -0
- data/test/helper.rb +14 -0
- metadata +39 -6
data/README.md
CHANGED
@@ -37,7 +37,9 @@ bounce
|
|
37
37
|
respond_with article.bounce(params[:article])
|
38
38
|
end
|
39
39
|
|
40
|
-
If you
|
40
|
+
If you have more than one controller, extract the `respond_to :html` into the application controller.
|
41
|
+
|
42
|
+
If you use [decent_exposure](https://github.com/voxdolo/decent_exposure) you can do this:
|
41
43
|
|
42
44
|
respond_to :html
|
43
45
|
expose(:article)
|
@@ -47,14 +49,6 @@ bounce
|
|
47
49
|
end
|
48
50
|
alias update create
|
49
51
|
|
50
|
-
If you have more than one controller, I'll bet you do, extract the `respond_to :html` into the application controller. Now this:
|
51
|
-
|
52
|
-
expose(:article)
|
53
|
-
|
54
|
-
def create
|
55
|
-
respond_with article.bounce
|
56
|
-
end
|
57
|
-
alias update create
|
58
52
|
|
59
53
|
Install
|
60
54
|
-------
|
data/Rakefile
CHANGED
data/lib/bounce/railtie.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module Bounce
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer 'bounce.initialize' do
|
4
|
+
ActiveSupport.on_load(:active_record) do
|
5
|
+
Bounce::Railtie.insert
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Railtie
|
11
|
+
def self.insert
|
12
|
+
ActiveRecord::Base.send :include, Bounce::ActiveRecordExtension
|
13
|
+
end
|
4
14
|
end
|
5
15
|
end
|
data/lib/bounce/version.rb
CHANGED
data/test/bounce_test.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class BounceTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_return_object
|
7
|
+
article = Article.new(:name => 'foobar')
|
8
|
+
subject = article.bounce
|
9
|
+
assert_equal true, subject.persisted?
|
10
|
+
assert_equal Article, subject.class
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_save_new_object
|
14
|
+
article = Article.new(:name => 'foo')
|
15
|
+
subject = article.bounce
|
16
|
+
assert_equal true, subject.persisted?
|
17
|
+
assert_equal 'foo', subject.name
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_save_new_object_invalid
|
21
|
+
article = Article.new(:name => '')
|
22
|
+
subject = article.bounce
|
23
|
+
assert_equal false, subject.persisted?
|
24
|
+
assert_equal false, subject.valid?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_save_existing_object
|
28
|
+
article = Article.create(:name => 'foo')
|
29
|
+
article.name = 'bar'
|
30
|
+
subject = article.bounce
|
31
|
+
assert_equal false, subject.changed?
|
32
|
+
assert_equal 'bar', subject.name
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_save_existing_object_invalid
|
36
|
+
article = Article.create(:name => 'foo')
|
37
|
+
article.name = ''
|
38
|
+
subject = article.bounce
|
39
|
+
assert_equal true, subject.changed?
|
40
|
+
assert_equal false, subject.valid?
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_update_attributes_of_new_object
|
44
|
+
article = Article.new
|
45
|
+
subject = article.bounce(:name => 'foo')
|
46
|
+
assert_equal true, subject.persisted?
|
47
|
+
assert_equal 'foo', subject.name
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_update_attributes_of_new_object_invalid
|
51
|
+
article = Article.new
|
52
|
+
subject = article.bounce(:name => '')
|
53
|
+
assert_equal false, subject.persisted?
|
54
|
+
assert_equal false, subject.valid?
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_update_attributes_of_existing_object
|
58
|
+
article = Article.create(:name => 'foo')
|
59
|
+
subject = article.bounce(:name => 'bar')
|
60
|
+
assert_equal false, subject.changed?
|
61
|
+
assert_equal 'bar', subject.name
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_update_attributes_of_existing_object_invalid
|
65
|
+
article = Article.create(:name => 'foo')
|
66
|
+
subject = article.bounce(:name => '')
|
67
|
+
assert_equal true, subject.changed?
|
68
|
+
assert_equal false, subject.valid?
|
69
|
+
end
|
70
|
+
end
|
Binary file
|
data/test/helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'redgreen'
|
4
|
+
require 'bounce'
|
5
|
+
|
6
|
+
ActiveRecord::Base.establish_connection \
|
7
|
+
:adapter => 'sqlite3',
|
8
|
+
:database => File.dirname(__FILE__) + '/fixtures/bounce.sqlite3'
|
9
|
+
load File.dirname(__FILE__) + '/fixtures/schema.rb'
|
10
|
+
load File.dirname(__FILE__) + '/fixtures/article.rb'
|
11
|
+
|
12
|
+
Bounce::Railtie.insert
|
13
|
+
|
14
|
+
class Test::Unit::TestCase; end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Thomas Marino
|
@@ -15,11 +15,39 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-09 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: sqlite3-ruby
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activerecord
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 7
|
44
|
+
segments:
|
45
|
+
- 3
|
46
|
+
- 0
|
47
|
+
version: "3.0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: "\n\n `bounce` will save and return an active record object. This results in a nice refactor of update and create actions in your controllers when used with `respond_with`.\n "
|
23
51
|
email: writejm@gmail.com
|
24
52
|
executables: []
|
25
53
|
|
@@ -35,6 +63,11 @@ files:
|
|
35
63
|
- lib/bounce/railtie.rb
|
36
64
|
- lib/bounce/version.rb
|
37
65
|
- lib/bounce.rb
|
66
|
+
- test/bounce_test.rb
|
67
|
+
- test/fixtures/article.rb
|
68
|
+
- test/fixtures/bounce.sqlite3
|
69
|
+
- test/fixtures/schema.rb
|
70
|
+
- test/helper.rb
|
38
71
|
has_rdoc: true
|
39
72
|
homepage: http://github.com/johmas/bounce
|
40
73
|
licenses: []
|