fallback 0.1.0 → 0.1.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fallback}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-05-04}
12
+ s.date = %q{2010-05-06}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.files = [
15
15
  "Rakefile",
@@ -32,7 +32,7 @@ module Fallback
32
32
  # {:if => :a, :unless => :a} --> [true, false].all? --> false
33
33
  conditions.map do |condition, value|
34
34
  result = !!(value.respond_to?(:call) ? value.call(self) : send(value))
35
- condition == :unless ? result : !result
35
+ condition == :if ? result : !result
36
36
  end.all?
37
37
  end
38
38
 
@@ -28,6 +28,12 @@ class User4 < ActiveRecord::Base
28
28
  fallback :name => :description, :if => lambda{|u| u.xxx}
29
29
  end
30
30
 
31
+ class User5 < ActiveRecord::Base
32
+ include Fallback
33
+ set_table_name :users
34
+ fallback :name => :description, :if => :xxx
35
+ end
36
+
31
37
 
32
38
  describe Fallback do
33
39
  describe 'without delegation' do
@@ -93,13 +99,34 @@ describe Fallback do
93
99
 
94
100
  it "returns original if lambda returns false" do
95
101
  @user.stub!(:xxx).and_return false
96
- @user.name.should == 'D'
102
+ @user.name.should == 'N'
97
103
  end
98
104
 
99
105
  it "delegates if lambda returns true" do
100
106
  @user.stub!(:xxx).and_return true
107
+ @user.name.should == 'D'
108
+ end
109
+ end
110
+
111
+ describe 'with method as symbol' do
112
+ before do
113
+ @user = User5.new(:name => 'N', :description => 'D')
114
+ end
115
+
116
+ it "asks method" do
117
+ @user.should_receive(:xxx).and_return true
118
+ @user.name
119
+ end
120
+
121
+ it "returns original if method returns false" do
122
+ @user.stub!(:xxx).and_return false
101
123
  @user.name.should == 'N'
102
124
  end
125
+
126
+ it "delegates if method returns true" do
127
+ @user.stub!(:xxx).and_return true
128
+ @user.name.should == 'D'
129
+ end
103
130
  end
104
131
 
105
132
  describe "without fallback" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-04 00:00:00 +02:00
17
+ date: 2010-05-06 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20