molo 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/Molo.gemspec +56 -2
  2. data/README.markdown +31 -7
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/lib/tasks/molo.rb +9 -3
  6. data/vendor/rails_sql_views/.gitignore +3 -0
  7. data/vendor/rails_sql_views/CHANGELOG +22 -0
  8. data/vendor/rails_sql_views/CONTRIB +8 -0
  9. data/vendor/rails_sql_views/LICENSE +7 -0
  10. data/vendor/rails_sql_views/README +51 -0
  11. data/vendor/rails_sql_views/Rakefile +74 -0
  12. data/vendor/rails_sql_views/TODO +2 -0
  13. data/vendor/rails_sql_views/VERSION +1 -0
  14. data/vendor/rails_sql_views/init.rb +1 -0
  15. data/vendor/rails_sql_views/lib/active_record/view.rb +76 -0
  16. data/vendor/rails_sql_views/lib/core_ext/module.rb +13 -0
  17. data/vendor/rails_sql_views/lib/rails_sql_views.rb +47 -0
  18. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/abstract/schema_definitions.rb +63 -0
  19. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/abstract/schema_statements.rb +79 -0
  20. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/abstract_adapter.rb +41 -0
  21. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/mysql2_adapter.rb +62 -0
  22. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/mysql_adapter.rb +62 -0
  23. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oci_adapter.rb +33 -0
  24. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oracle_adapter.rb +33 -0
  25. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oracleenhanced_adapter.rb +39 -0
  26. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/oracleenhanced_adapter.rb.orig +72 -0
  27. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb +65 -0
  28. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig +69 -0
  29. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlite_adapter.rb +66 -0
  30. data/vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb +43 -0
  31. data/vendor/rails_sql_views/lib/rails_sql_views/loader.rb +18 -0
  32. data/vendor/rails_sql_views/lib/rails_sql_views/schema_dumper.rb +112 -0
  33. data/vendor/rails_sql_views/lib/rails_sql_views/version.rb +9 -0
  34. data/vendor/rails_sql_views/rails/init.rb +1 -0
  35. data/vendor/rails_sql_views/rails_sql_views.gemspec +81 -0
  36. data/vendor/rails_sql_views/test/.gitignore +1 -0
  37. data/vendor/rails_sql_views/test/README +63 -0
  38. data/vendor/rails_sql_views/test/adapter_test.rb +82 -0
  39. data/vendor/rails_sql_views/test/connection.example.yml +12 -0
  40. data/vendor/rails_sql_views/test/connection/native_mysql/connection.rb +32 -0
  41. data/vendor/rails_sql_views/test/connection/native_mysql/schema.sql +33 -0
  42. data/vendor/rails_sql_views/test/connection/native_postgresql/connection.rb +31 -0
  43. data/vendor/rails_sql_views/test/connection/native_postgresql/schema.sql +33 -0
  44. data/vendor/rails_sql_views/test/connection/oracle_enhanced/connection.rb +29 -0
  45. data/vendor/rails_sql_views/test/connection/oracle_enhanced/procedures.sql +15 -0
  46. data/vendor/rails_sql_views/test/connection/oracle_enhanced/schema.sql +39 -0
  47. data/vendor/rails_sql_views/test/models/item.rb +4 -0
  48. data/vendor/rails_sql_views/test/models/person.rb +5 -0
  49. data/vendor/rails_sql_views/test/models/person2.rb +3 -0
  50. data/vendor/rails_sql_views/test/models/place.rb +2 -0
  51. data/vendor/rails_sql_views/test/models/v_person.rb +4 -0
  52. data/vendor/rails_sql_views/test/models/v_profile.rb +3 -0
  53. data/vendor/rails_sql_views/test/schema.native_mysql.expected.rb +51 -0
  54. data/vendor/rails_sql_views/test/schema.native_postgresql.expected.rb +51 -0
  55. data/vendor/rails_sql_views/test/schema.oracle_enhanced.expected.rb +51 -0
  56. data/vendor/rails_sql_views/test/schema_dumper_test.rb +117 -0
  57. data/vendor/rails_sql_views/test/test_helper.rb +30 -0
  58. data/vendor/rails_sql_views/test/view_model_test.rb +63 -0
  59. data/vendor/rails_sql_views/test/view_operations_test.rb +36 -0
  60. data/vendor/yaml_db/lib/serialization_helper.rb +15 -10
  61. metadata +58 -4
@@ -0,0 +1,9 @@
1
+ module RailsSqlViews
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 7
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require 'rails_sql_views'
@@ -0,0 +1,81 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rails_sql_views}
8
+ s.version = "0.8.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Anthony Eden"]
12
+ s.date = %q{2010-08-25}
13
+ s.description = %q{Adds support for using SQL views within ActiveRecord}
14
+ s.email = %q{josh@technicalpickles.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README",
18
+ "TODO"
19
+ ]
20
+ s.files = [
21
+ "CHANGELOG",
22
+ "README",
23
+ "Rakefile",
24
+ "lib/active_record/view.rb",
25
+ "lib/core_ext/module.rb",
26
+ "lib/rails_sql_views.rb",
27
+ "lib/rails_sql_views/connection_adapters/abstract/schema_definitions.rb",
28
+ "lib/rails_sql_views/connection_adapters/abstract/schema_statements.rb",
29
+ "lib/rails_sql_views/connection_adapters/abstract_adapter.rb",
30
+ "lib/rails_sql_views/connection_adapters/mysql_adapter.rb",
31
+ "lib/rails_sql_views/connection_adapters/oci_adapter.rb",
32
+ "lib/rails_sql_views/connection_adapters/oracle_adapter.rb",
33
+ "lib/rails_sql_views/connection_adapters/oracleenhanced_adapter.rb",
34
+ "lib/rails_sql_views/connection_adapters/oracleenhanced_adapter.rb.orig",
35
+ "lib/rails_sql_views/connection_adapters/postgresql_adapter.rb",
36
+ "lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig",
37
+ "lib/rails_sql_views/connection_adapters/sqlite_adapter.rb",
38
+ "lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb",
39
+ "lib/rails_sql_views/loader.rb",
40
+ "lib/rails_sql_views/schema_dumper.rb",
41
+ "lib/rails_sql_views/version.rb"
42
+ ]
43
+ s.homepage = %q{http://activewarehouse.rubyforge.org/rails_sql_views}
44
+ s.rdoc_options = ["--charset=UTF-8"]
45
+ s.require_paths = ["lib"]
46
+ s.rubygems_version = %q{1.3.6}
47
+ s.summary = %q{Library which adds SQL Views to ActiveRecord.}
48
+ s.test_files = [
49
+ "test/adapter_test.rb",
50
+ "test/connection/native_mysql/connection.rb",
51
+ "test/connection/native_postgresql/connection.rb",
52
+ "test/connection/oracle_enhanced/connection.rb",
53
+ "test/models/item.rb",
54
+ "test/models/person.rb",
55
+ "test/models/person2.rb",
56
+ "test/models/place.rb",
57
+ "test/models/v_person.rb",
58
+ "test/models/v_profile.rb",
59
+ "test/schema.native_mysql.expected.rb",
60
+ "test/schema.native_postgresql.expected.rb",
61
+ "test/schema.oracle_enhanced.expected.rb",
62
+ "test/schema_dumper_test.rb",
63
+ "test/test_helper.rb",
64
+ "test/view_model_test.rb",
65
+ "test/view_operations_test.rb"
66
+ ]
67
+
68
+ if s.respond_to? :specification_version then
69
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
70
+ s.specification_version = 3
71
+
72
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
74
+ else
75
+ s.add_dependency(%q<activerecord>, [">= 0"])
76
+ end
77
+ else
78
+ s.add_dependency(%q<activerecord>, [">= 0"])
79
+ end
80
+ end
81
+
@@ -0,0 +1 @@
1
+ *.out.rb
@@ -0,0 +1,63 @@
1
+ == Executing Tests
2
+
3
+ First create the test database: rails_sql_views_unittest
4
+
5
+ Next, copy test/connection.example.yml to test/connection.yml and change the
6
+ settings to match your database configuration that you are testing.
7
+
8
+ To run the tests either use:
9
+
10
+ rake
11
+
12
+ Which will run the MySQL tests, or use something like the following:
13
+
14
+ rake DB=native_postgresql
15
+
16
+ Substituting the directory name inside the connection directory.
17
+
18
+ == Status
19
+
20
+ Currently the following adapters have been tested:
21
+
22
+ * MySQL
23
+ * PostgreSQL Pure Ruby
24
+
25
+ The Oracle and SQL Server adapters have not been tested by me.
26
+
27
+ == Implementing Adapters
28
+
29
+ If you would like to implement an adapter, it should go in
30
+ lib/rails_sql_views/connection_adapters. Follow the conventions
31
+ of the other adapters currently implemented. Every adapter must implement the
32
+ following methods:
33
+
34
+ supports_views?
35
+ base_tables(name = nil)
36
+ views(name = nil)
37
+ view_select_statement(view, name=nil)
38
+
39
+ The suports_views? method must return true. The views method must return an
40
+ array of all view names. The view_select_statement method must return the
41
+ select statement used to construct the specified view.
42
+
43
+ In addition you must include the following for testing purposes:
44
+
45
+ The script which establishes the database connection in ActiveRecord:
46
+
47
+ test/connection/driver_name/connection.rb
48
+
49
+ The schema to setup the test database in your drivers native form:
50
+
51
+ test/connection/driver_name/schema.sql
52
+
53
+ The expected schema output from a schema dump. Note that it must be formatted
54
+ *exactly* as the output would be:
55
+
56
+ test/schema.driver_name.out.rb
57
+
58
+ Once this is done you should send the diff of the changes to
59
+ anthonyeden@gmail.com. Any questions can also be emailed to this address.
60
+
61
+ == Known Issues
62
+
63
+ * If you are running on Rails 1.1.6 then the schema dumper test will fail because the formatting of the schema output has changed between 1.1.6 and 1.2.
@@ -0,0 +1,82 @@
1
+ require "#{File.dirname(__FILE__)}/test_helper"
2
+
3
+ class AdapterTest < Test::Unit::TestCase
4
+ def test_current_database
5
+ if ActiveRecord::Base.connection.respond_to?(:current_database)
6
+ assert_equal 'rails_sql_views_unittest', ActiveRecord::Base.connection.current_database
7
+ end
8
+ end
9
+ def test_tables
10
+ create_view
11
+ found = ActiveRecord::Base.connection.tables.sort
12
+ found.delete(ActiveRecord::Migrator.schema_migrations_table_name)
13
+ assert_equal ["items", "items_people", "people", "people2", "places", "v_people"], found
14
+ end
15
+ def test_base_tables
16
+ create_view
17
+ found = ActiveRecord::Base.connection.base_tables.sort
18
+ found.delete(ActiveRecord::Migrator.schema_migrations_table_name)
19
+ assert_equal ["items", "items_people", "people", "people2", "places"], found
20
+ end
21
+ def test_views
22
+ create_view
23
+ assert_equal ['v_people'], ActiveRecord::Base.connection.views
24
+ end
25
+ def test_columns
26
+ create_view
27
+ assert_equal ["f_name", "l_name", "social_security"], ActiveRecord::Base.connection.columns('v_people').collect { |c| c.name }
28
+ end
29
+ def test_supports_views
30
+ assert ActiveRecord::Base.connection.supports_views?
31
+ end
32
+
33
+ def test_mapped_views
34
+ create_mapping
35
+ assert_equal ['v_people'], ActiveRecord::Base.connection.views
36
+ end
37
+ def test_mapped_columns
38
+ create_mapping
39
+ assert_equal ["f_name", "l_name", "address_id"], ActiveRecord::Base.connection.columns('v_people').collect { |c| c.name }
40
+ end
41
+
42
+ def test_view_select_statement
43
+ case ActiveRecord::Base.connection.adapter_name
44
+ when "MySQL"
45
+ assert_equal "select `people`.`first_name` AS `f_name`,`people`.`last_name` AS `l_name`,`people`.`ssn` AS `social_security` from `people`", ActiveRecord::Base.connection.view_select_statement('v_people')
46
+ when "PostgreSQL"
47
+ assert_equal "SELECT people.first_name AS f_name, people.last_name AS l_name, people.ssn AS social_security FROM people;", ActiveRecord::Base.connection.view_select_statement('v_people')
48
+ end
49
+ end
50
+
51
+ def test_old_name_not_found_error_during_mapping
52
+ assert_raise ActiveRecord::ActiveRecordError do
53
+ ActiveRecord::Base.connection.create_mapping_view(:people, :v_people, :force => true) do |v|
54
+ v.map_column :foo, :bar
55
+ end
56
+ end
57
+ end
58
+
59
+ ### TODO
60
+ # def test_only_base_table_triggers_are_dropped_for_disabled_ref_integrity
61
+ # ActiveRecord::Base.connection.disable_referential_integrity do
62
+ # end
63
+ # end
64
+
65
+ private
66
+ def create_view
67
+ ActiveRecord::Base.connection.create_view(:v_people, 'select first_name, last_name, ssn from people', :force => true) do |v|
68
+ v.column :f_name
69
+ v.column :l_name
70
+ v.column :social_security
71
+ end
72
+ end
73
+
74
+ def create_mapping
75
+ ActiveRecord::Base.connection.create_mapping_view(:people, :v_people, :force => true) do |v|
76
+ v.map_column :id, nil
77
+ v.map_column :first_name, :f_name
78
+ v.map_column :last_name, :l_name
79
+ v.map_column :ssn, nil
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,12 @@
1
+ postgresql:
2
+ username: postgres
3
+ password:
4
+ host: localhost
5
+ database: rails_sql_views_unittest
6
+ encoding: utf8
7
+ schema_file: schema.sql
8
+ mysql:
9
+ username: root
10
+ host: localhost
11
+ database: rails_sql_views_unittest
12
+ schema_file: schema.sql
@@ -0,0 +1,32 @@
1
+ print "Using native MySQL\n"
2
+
3
+ adapter_name = 'mysql'
4
+ config = YAML.load_file(File.join(File.dirname(__FILE__), '/../../connection.yml'))[adapter_name]
5
+
6
+ #require 'logger'
7
+ #ActiveRecord::Base.logger = Logger.new("debug.log")
8
+
9
+ ActiveRecord::Base.silence do
10
+ ActiveRecord::Base.configurations = {
11
+ config['database'] => {
12
+ :adapter => adapter_name,
13
+ :username => config['username'],
14
+ :password => config['password'],
15
+ :host => config['host'],
16
+ :database => config['database'],
17
+ :encoding => config['encoding'],
18
+ :schema_file => config['schema_file'],
19
+ }
20
+ }
21
+
22
+ ActiveRecord::Base.establish_connection config['database']
23
+ ActiveRecord::Migration.verbose = false
24
+
25
+ puts "Resetting database"
26
+ conn = ActiveRecord::Base.connection
27
+ conn.recreate_database(conn.current_database)
28
+ conn.reconnect!
29
+ lines = open(File.join(File.dirname(__FILE__), ActiveRecord::Base.configurations[config['database']][:schema_file])).readlines
30
+ lines.join.split(';').each { |line| conn.execute(line) }
31
+ conn.reconnect!
32
+ end
@@ -0,0 +1,33 @@
1
+ drop table if exists people;
2
+ create table people (
3
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
4
+ first_name char(255),
5
+ last_name char(255),
6
+ ssn char(64),
7
+ address_id integer
8
+ );
9
+ drop table if exists people2;
10
+ create table people2 (
11
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
12
+ first_name char(255),
13
+ last_name char(255),
14
+ ssn char(64)
15
+ );
16
+ drop table if exists places;
17
+ create table places (
18
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
19
+ address text,
20
+ city char(255),
21
+ cstate char(255),
22
+ country char(2)
23
+ );
24
+ drop table if exists items;
25
+ create table items (
26
+ id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
27
+ person_id int(11)
28
+ );
29
+ drop table if exists items_people;
30
+ create table items_people (
31
+ person_id int(11),
32
+ item_id int(11)
33
+ );
@@ -0,0 +1,31 @@
1
+ print "Using native PostgreSQL\n"
2
+
3
+ adapter_name = 'postgresql'
4
+ config = YAML.load_file(File.join(File.dirname(__FILE__), '/../../connection.yml'))[adapter_name]
5
+
6
+ #require 'logger'
7
+ #ActiveRecord::Base.logger = Logger.new("debug.log")
8
+
9
+ ActiveRecord::Base.silence do
10
+ ActiveRecord::Base.configurations = {
11
+ 'rails_sql_views_unittest' => {
12
+ :adapter => adapter_name,
13
+ :username => config['username'],
14
+ :password => config['password'],
15
+ :host => config['host'],
16
+ :database => config['database'],
17
+ :encoding => config['encoding'],
18
+ :schema_file => config['schema_file'],
19
+ }
20
+ }
21
+
22
+ ActiveRecord::Base.establish_connection config['database']
23
+
24
+ puts "Resetting database"
25
+ conn = ActiveRecord::Base.connection
26
+ #conn.recreate_database(conn.current_database)
27
+ conn.reconnect!
28
+ lines = open(File.join(File.dirname(__FILE__), ActiveRecord::Base.configurations[config['database']][:schema_file])).readlines
29
+ lines.join.split(';').each { |line| conn.execute(line) }
30
+ conn.reconnect!
31
+ end
@@ -0,0 +1,33 @@
1
+ drop table if exists people CASCADE;
2
+ create table people (
3
+ id serial primary key,
4
+ first_name char(255),
5
+ last_name char(255),
6
+ ssn char(64),
7
+ address_id integer
8
+ );
9
+ drop table if exists people2 CASCADE;
10
+ create table people2 (
11
+ id serial primary key,
12
+ first_name char(255),
13
+ last_name char(255),
14
+ ssn char(64)
15
+ );
16
+ drop table if exists places CASCADE;
17
+ create table places (
18
+ id serial primary key,
19
+ address text,
20
+ city char(255),
21
+ cstate char(255),
22
+ country char(2)
23
+ );
24
+ drop table if exists items CASCADE;
25
+ create table items (
26
+ id serial primary key,
27
+ person_id integer
28
+ );
29
+ drop table if exists items_people CASCADE;
30
+ create table items_people (
31
+ person_id integer,
32
+ item_id integer
33
+ );
@@ -0,0 +1,29 @@
1
+ print "Using Oracle Enhanced\n"
2
+
3
+ #require 'logger'
4
+ #ActiveRecord::Base.logger = Logger.new("debug.log")
5
+
6
+ ActiveRecord::Base.configurations = {
7
+ 'rails_sql_views_unittest' => {
8
+ :adapter => :oracle_enhanced,
9
+ :username => 'rails_sql_views_unittest',
10
+ :password => 'rails',
11
+ :host => 'localhost',
12
+ :database => 'mydev',
13
+ :encoding => 'utf8',
14
+ :procedures_file => 'procedures.sql',
15
+ :schema_file => 'schema.sql',
16
+ }
17
+ }
18
+
19
+ ActiveRecord::Base.establish_connection 'rails_sql_views_unittest'
20
+
21
+ puts "Resetting database"
22
+ conn = ActiveRecord::Base.connection
23
+ #conn.recreate_database(conn.current_database)
24
+ conn.reconnect!
25
+ [:procedures_file, :schema_file].each do |file|
26
+ lines = open(File.join(File.dirname(__FILE__), ActiveRecord::Base.configurations['rails_sql_views_unittest'][file])).readlines
27
+ conn.execute(lines.to_s)
28
+ end
29
+ conn.reconnect!
@@ -0,0 +1,15 @@
1
+ create or replace
2
+ procedure dropTable (tab_name varchar2) as
3
+ this_tab_name user_tables.table_name%type;
4
+ cursor table_cur is
5
+ select table_name
6
+ from user_tables
7
+ where table_name = tab_name;
8
+ begin
9
+ open table_cur;
10
+ loop
11
+ fetch table_cur into this_tab_name;
12
+ exit when table_cur%notfound;
13
+ execute immediate 'drop table "' || this_tab_name || '"';
14
+ end loop;
15
+ end;
@@ -0,0 +1,39 @@
1
+ BEGIN
2
+ dropTable('PEOPLE');
3
+ EXECUTE IMMEDIATE 'create table people (
4
+ id integer primary key,
5
+ first_name varchar2(255),
6
+ last_name varchar2(255),
7
+ ssn varchar2(64),
8
+ address_id integer
9
+ )';
10
+
11
+ dropTable('PEOPLE2');
12
+ EXECUTE IMMEDIATE 'create table people2 (
13
+ id integer primary key,
14
+ first_name varchar2(255),
15
+ last_name varchar2(255),
16
+ ssn varchar2(64)
17
+ )';
18
+
19
+ dropTable('PLACES');
20
+ EXECUTE IMMEDIATE 'create table places (
21
+ id integer primary key,
22
+ address varchar2(2000),
23
+ city varchar2(255),
24
+ cstate varchar2(255),
25
+ country char(2)
26
+ )';
27
+
28
+ dropTable('ITEMS');
29
+ EXECUTE IMMEDIATE 'create table items (
30
+ id integer primary key,
31
+ person_id integer
32
+ )';
33
+
34
+ dropTable('ITEMS_PEOPLE');
35
+ EXECUTE IMMEDIATE 'create table items_people (
36
+ person_id integer,
37
+ item_id integer
38
+ )';
39
+ END;