updateable_views_inheritance 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -2
- data/CHANGELOG.md +28 -0
- data/README.rdoc +18 -12
- data/Rakefile +2 -0
- data/lib/generators/updateable_views_inheritance/install_generator.rb +20 -0
- data/lib/generators/{updateable_views_inheritance_migration/templates/migration.rb → updateable_views_inheritance/templates/create_updateable_views_inheritance.rb} +3 -3
- data/lib/updateable_views_inheritance/version.rb +2 -2
- data/tasks/updateable_views_inheritance_tasks.rake +0 -8
- data/test/content_test.rb +1 -1
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/bicycle.rb +3 -0
- data/test/dummy/app/models/boat.rb +3 -0
- data/test/dummy/app/models/car.rb +3 -0
- data/test/dummy/app/models/electric_locomotive.rb +3 -0
- data/test/dummy/app/models/electric_train.rb +3 -0
- data/test/{app → dummy/app}/models/locomotive.rb +1 -1
- data/test/{app → dummy/app}/models/maglev_locomotive.rb +1 -1
- data/test/dummy/app/models/maglev_train.rb +3 -0
- data/test/dummy/app/models/rack_locomotive.rb +3 -0
- data/test/dummy/app/models/rack_train.rb +3 -0
- data/test/dummy/app/models/railed_vehicle.rb +3 -0
- data/test/dummy/app/models/steam_locomotive.rb +3 -0
- data/test/dummy/app/models/steam_train.rb +3 -0
- data/test/dummy/app/models/train.rb +3 -0
- data/test/{app → dummy/app}/models/vehicle.rb +1 -0
- data/test/dummy/app/models/wheeled_vehicle.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/{database.yml → dummy/config/database.yml} +1 -1
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/fixtures/migrations/{1_add_class_table_inheritance.rb → 1_add_updateable_views_inheritance.rb} +1 -1
- data/test/install_generator_test.rb +13 -0
- data/test/migration_test.rb +1 -1
- data/test/schema_test.rb +1 -1
- data/test/test_helper.rb +5 -67
- data/updateable_views_inheritance.gemspec +4 -3
- metadata +118 -42
- data/lib/generators/updateable_views_inheritance_migration/USAGE +0 -8
- data/lib/generators/updateable_views_inheritance_migration/uvi_migration_generator.rb +0 -12
- data/test/app/models/bicycle.rb +0 -3
- data/test/app/models/boat.rb +0 -3
- data/test/app/models/car.rb +0 -3
- data/test/app/models/electric_locomotive.rb +0 -3
- data/test/app/models/electric_train.rb +0 -3
- data/test/app/models/maglev_train.rb +0 -3
- data/test/app/models/rack_locomotive.rb +0 -3
- data/test/app/models/rack_train.rb +0 -3
- data/test/app/models/railed_vehicle.rb +0 -3
- data/test/app/models/steam_locomotive.rb +0 -3
- data/test/app/models/steam_train.rb +0 -3
- data/test/app/models/train.rb +0 -3
- data/test/app/models/wheeled_vehicle.rb +0 -3
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
## 1.1.2 (14 June 2013)
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
|
5
|
+
- fixed generating migration on installation
|
6
|
+
|
7
|
+
Documentation:
|
8
|
+
|
9
|
+
- README brought up to date
|
10
|
+
|
11
|
+
## 1.1.1 (14 June 2013)
|
12
|
+
|
13
|
+
Features:
|
14
|
+
|
15
|
+
- gemified and released on rubygems.org
|
16
|
+
|
17
|
+
## 1.1.0 (13 June 2013)
|
18
|
+
|
19
|
+
Features:
|
20
|
+
|
21
|
+
- updated for rails 3.2.x
|
22
|
+
|
23
|
+
## 1.0.0 (14 September 2009)
|
24
|
+
|
25
|
+
Features:
|
26
|
+
|
27
|
+
- class_table_inheritance plugin has behaved stably in production for a year
|
28
|
+
- supports rails 2.1, 2.2 and 2.3
|
data/README.rdoc
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Class Table Inheritance for ActiveRecord using updateable views.
|
4
4
|
|
5
5
|
More about the pattern on http://www.martinfowler.com/eaaCatalog/classTableInheritance.html. This gem messes very little with Rails inheritance mechanism.
|
6
|
-
Instead it relies on updatable views in the database to represent classes in the inheritance chain. The approach was first
|
6
|
+
Instead it relies on updatable views in the database to represent classes in the inheritance chain. The approach was {first suggested by John
|
7
7
|
Wilger}[http://web.archive.org/web/20060408145717/johnwilger.com/articles/2005/09/29/class-table-inheritance-in-rails-with-postgresql].
|
8
8
|
|
9
9
|
|
@@ -16,21 +16,26 @@ Ruby: tested with 1.8.7 and 1.9.3
|
|
16
16
|
Database: PostgreSQL 8.1+ only. Patches for other DBMS are welcome. Note that you are not required to use updateable views, children relations can be tables (with some triggers involved) or materialized views.
|
17
17
|
|
18
18
|
==Install
|
19
|
-
|
19
|
+
Run
|
20
20
|
gem install updateable_views_inheritance
|
21
21
|
|
22
22
|
==Usage
|
23
23
|
|
24
24
|
===Setup
|
25
25
|
|
26
|
-
In Gemfile
|
26
|
+
* In <tt>Gemfile</tt> add <tt>gem 'updateable_views_inheritance'</tt>
|
27
|
+
* Run <tt>rails generate updateable_views_inheritance:install && rake db:migrate</tt>
|
28
|
+
* In <tt>config/database.yml</tt> аdd to every environment
|
29
|
+
|
30
|
+
prepared_statements: false
|
31
|
+
|
32
|
+
ActiveRecord's postgresql adapter has subtle problems with prepared statements that cause strange errors every now and then.
|
33
|
+
* In <tt>config/environment.rb</tt> set <tt>config.active_record.schema_format = :sql</tt>
|
34
|
+
* In case you're using fixtures, don't forget to run
|
27
35
|
|
28
|
-
|
36
|
+
rake updateable_views_inheritance:fixture
|
29
37
|
|
30
|
-
|
31
|
-
1. <tt>rake updateable_views_inheritance:setup</tt> to create a migration.
|
32
|
-
1. <tt>rake db:migrate</tt>.
|
33
|
-
1. In <tt>config/environment.rb</tt> set <tt>config.active_record.schema_format = :sql</tt>. Database views and rules are not supported in default schema.rb.
|
38
|
+
after every change to the class hierarchy. Otherwise tests may fail.
|
34
39
|
|
35
40
|
===Example
|
36
41
|
|
@@ -98,13 +103,14 @@ Note that you should remove only leaf classes (i.e. those that do not have desce
|
|
98
103
|
|
99
104
|
==Compatibility with Single Table Inheritance
|
100
105
|
|
101
|
-
The approach of this gem is completely independent from Rails
|
106
|
+
The approach of this gem is completely independent from Rails built-in Single Table Inheritance. STI and CLTI can safely be mixed in one inheritance chain.
|
102
107
|
|
103
108
|
==Testing Your App
|
104
109
|
|
105
|
-
|
106
|
-
inheritors' tables won't be bumped to the max and it might not be possible to save objects!</b>
|
110
|
+
If you use fixtures, you must run <tt>rake updateable_views_inheritance:fixture</tt> to generate fixture for the updateable_views_inheritance table after you add/remove
|
111
|
+
classes from the hierarchy or change underlying table or view names. <b>Without it primary key sequence for inheritors' tables won't be bumped to the max and it might not be possible to save objects!</b> If you don't use fixtures for the classes in the hierarchy you don't need to do that.
|
107
112
|
|
108
|
-
This gem re-enables referential integrity on fixture loading, so if you are using foreign keys you will have to explicitly declare fixture load order in test_helper.rb
|
113
|
+
This gem re-enables referential integrity on fixture loading, so if you are using foreign keys you will have to explicitly declare fixture load order in test_helper.rb, for
|
114
|
+
example:
|
109
115
|
|
110
116
|
fixtures(:roots, :trunks, :leafs, ...)
|
data/Rakefile
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
|
5
|
+
module UpdateableViewsInheritance
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
extend ActiveRecord::Generators::Migration
|
10
|
+
|
11
|
+
desc "Creates a migration that creates a special table used by the updateable_views_inheritance gem."
|
12
|
+
source_root File.expand_path('../templates', __FILE__)
|
13
|
+
|
14
|
+
def create_migration
|
15
|
+
migration_file = "create_updateable_views_inheritance.rb"
|
16
|
+
migration_template migration_file, "db/migrate/#{migration_file}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class
|
2
|
-
def
|
1
|
+
class CreateUpdateableViewsInheritance < ActiveRecord::Migration
|
2
|
+
def up
|
3
3
|
create_table(:updateable_views_inheritance, :id => false) do |t|
|
4
4
|
t.column :parent_relation, :string, :null => false
|
5
5
|
t.column :child_aggregate_view, :string, :null => false
|
@@ -11,7 +11,7 @@ class <%= class_name %> < ActiveRecord::Migration
|
|
11
11
|
execute "ALTER TABLE updateable_views_inheritance ADD UNIQUE (parent_relation, child_aggregate_view)"
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def down
|
15
15
|
drop_table :updateable_views_inheritance
|
16
16
|
end
|
17
17
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "1.1.
|
1
|
+
module UpdateableViewsInheritance
|
2
|
+
VERSION = "1.1.2"
|
3
3
|
end
|
@@ -8,12 +8,4 @@ namespace :updateable_views_inheritance do
|
|
8
8
|
}.to_yaml)
|
9
9
|
f.close
|
10
10
|
end
|
11
|
-
|
12
|
-
desc 'Generate migration to create special table for the updateable_views_inheritance gem'
|
13
|
-
task :setup => :environment do
|
14
|
-
raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
|
15
|
-
require 'rails_generator'
|
16
|
-
require 'rails_generator/scripts/generate'
|
17
|
-
Rails::Generator::Scripts::Generate.new.run(["updateable_views_inheritance_migration", ENV["MIGRATION"] || "AddUpdatebleViewsInheritance"])
|
18
|
-
end
|
19
11
|
end
|
data/test/content_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
class
|
3
|
+
class UpdateableViewsInheritanceContentTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
5
5
|
ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 5)
|
6
6
|
# order of fixtures is important for the test - last loaded should not be with max(id)
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
File without changes
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "updateable_views_inheritance"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
15
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
16
|
+
|
17
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
18
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
19
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
20
|
+
|
21
|
+
# Activate observers that should always be running.
|
22
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
23
|
+
|
24
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
25
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
26
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
27
|
+
|
28
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
29
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
30
|
+
# config.i18n.default_locale = :de
|
31
|
+
|
32
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
33
|
+
config.encoding = "utf-8"
|
34
|
+
|
35
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
36
|
+
config.filter_parameters += [:password]
|
37
|
+
|
38
|
+
# Enable escaping HTML in JSON.
|
39
|
+
config.active_support.escape_html_entities_in_json = true
|
40
|
+
|
41
|
+
# Use SQL instead of Active Record's schema dumper when creating the database.
|
42
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
43
|
+
# like if you have constraints or database-specific column types
|
44
|
+
# config.active_record.schema_format = :sql
|
45
|
+
|
46
|
+
# Enforce whitelist mode for mass assignment.
|
47
|
+
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
48
|
+
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
49
|
+
# parameters by using an attr_accessible or attr_protected declaration.
|
50
|
+
config.active_record.whitelist_attributes = false
|
51
|
+
|
52
|
+
# Enable the asset pipeline
|
53
|
+
config.assets.enabled = true
|
54
|
+
|
55
|
+
# Version of your assets, change this if you want to expire all your assets
|
56
|
+
config.assets.version = '1.0'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Raise exception on mass assignment protection for Active Record models
|
26
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
27
|
+
|
28
|
+
# Log the query plan for queries taking more than this (works
|
29
|
+
# with SQLite, MySQL, and PostgreSQL)
|
30
|
+
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
31
|
+
|
32
|
+
# Do not compress assets
|
33
|
+
config.assets.compress = false
|
34
|
+
|
35
|
+
# Expands the lines which load the assets
|
36
|
+
config.assets.debug = true
|
37
|
+
end
|