falls_back_on 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/falls_back_on.rb CHANGED
@@ -8,6 +8,10 @@ module FallsBackOn
8
8
  end
9
9
 
10
10
  module InstanceMethods
11
+ def class_name
12
+ self.to_s
13
+ end
14
+
11
15
  def fallback
12
16
  Fallback.get_for(class_name)
13
17
  end
@@ -27,7 +27,8 @@ class Fallback < ActiveRecord::Base
27
27
  end
28
28
 
29
29
  def destroy_for(name)
30
- find_by_name(name).andand.destroy
30
+ fallback = find_by_name(name.to_s)
31
+ fallback.destroy unless fallback.nil?
31
32
  true
32
33
  end
33
34
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ class Arcade < ActiveRecord::Base
4
+ attr_accessor :pinball_count, :video_game_count
5
+
6
+ falls_back_on :pinball_count => 73
7
+ end
8
+
9
+ describe Fallback do
10
+ describe '.destroy_for' do
11
+ it 'should destroy a fallback' do
12
+ Fallback.create :name => 'Arcade'
13
+ expect do
14
+ Fallback.destroy_for Arcade
15
+ end.should change(Fallback, :count).by(-1)
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ class State < ActiveRecord::Base
4
+ falls_back_on :area => 10000
5
+ end
6
+
7
+ describe FallsBackOn do
8
+ describe '.class_name' do
9
+ it 'should return the class name' do
10
+ State.class_name.should == 'State'
11
+ end
12
+ end
13
+
14
+ describe '.set_fallback' do
15
+ it 'should create a Fallback for a class' do
16
+ State.set_fallback
17
+
18
+ fallback = Fallback.find_by_name 'State'
19
+ fallback.should be_an_instance_of(Fallback)
20
+ fallback.values.should == {:area => 10000 }
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'active_record'
12
+ require 'logger'
13
+
14
+ $:.unshift File.expand_path('../lib', __FILE__)
15
+ require 'falls_back_on'
16
+ require 'falls_back_on/active_record_ext'
17
+ require 'falls_back_on/app/models/fallback'
18
+
19
+ ActiveRecord::Base.logger = Logger.new nil
20
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
21
+
22
+ ActiveRecord::Schema.define(:version => 1) do
23
+ create_table "fallbacks", :force => true do |t|
24
+ t.string "name"
25
+ t.text "values"
26
+ t.datetime "created_at"
27
+ t.datetime "updated_at"
28
+ end
29
+
30
+ create_table 'states' do |t|
31
+ t.integer 'area'
32
+ end
33
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falls_back_on
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-13 00:00:00 -04:00
19
+ date: 2010-08-31 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -75,6 +75,38 @@ dependencies:
75
75
  - 0
76
76
  version: "0"
77
77
  requirement: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ type: :development
80
+ prerelease: false
81
+ name: sqlite3-ruby
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirement: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ type: :development
94
+ prerelease: false
95
+ name: rspec
96
+ version_requirements: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 62196427
102
+ segments:
103
+ - 2
104
+ - 0
105
+ - 0
106
+ - beta
107
+ - 20
108
+ version: 2.0.0.beta.20
109
+ requirement: *id006
78
110
  description: |
79
111
  = falls_back_on
80
112
 
@@ -109,6 +141,9 @@ files:
109
141
  - rails/init.rb
110
142
  - LICENSE
111
143
  - README.rdoc
144
+ - spec/lib/falls_back_on/app/models/fallback_spec.rb
145
+ - spec/lib/falls_back_on_spec.rb
146
+ - spec/spec_helper.rb
112
147
  has_rdoc: true
113
148
  homepage: http://github.com/dkastner/falls_back_on
114
149
  licenses: []
@@ -143,5 +178,7 @@ rubygems_version: 1.3.7
143
178
  signing_key:
144
179
  specification_version: 3
145
180
  summary: ActiveRecord extension to intelligently fall back on another column when a given column is unavailable
146
- test_files: []
147
-
181
+ test_files:
182
+ - spec/lib/falls_back_on/app/models/fallback_spec.rb
183
+ - spec/lib/falls_back_on_spec.rb
184
+ - spec/spec_helper.rb