copy_machine 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.
@@ -0,0 +1,29 @@
1
+ <script type="text/javascript" charset="utf-8">
2
+ if (typeof jQuery == 'undefined') {
3
+ var jquery_url = '/__rack_copy_machine__/jquery-1.4.2.min.js';
4
+ document.write(unescape('%3Cscript src="' + jquery_url + '" type="text/javascript"%3E%3C/script%3E'));
5
+ }
6
+ </script>
7
+ <script type="text/javascript" src="/__rack_copy_machine__/copy_machine.js"></script>
8
+ <style type="text/css" media="screen">
9
+ @import url(/__rack_copy_machine__/copy_machine.css);
10
+ </style>
11
+
12
+ <% unless ::CopyMachine.notifications.empty? %>
13
+ <span class="cm_notifier">
14
+ Copy Machine
15
+ <span class="cm_close_button">
16
+ </span>
17
+ </span>
18
+
19
+ <table id="copy_machine_traces" style="display:none">
20
+ <tbody>
21
+ <% ::CopyMachine.notifications.each do |n| %>
22
+ <tr>
23
+ <td><%= n[:backtrace] %></td>
24
+ <td><%= n[:sql] %></td>
25
+ </tr>
26
+ <% end %>
27
+ </tbody>
28
+ </table>
29
+ <% end %>
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+ require 'rails'
3
+
4
+ describe CopyMachine::Configuration do
5
+ before do
6
+ @config = CopyMachine::Configuration.config
7
+ @proc = Proc.new { puts 'foo '}
8
+ end
9
+
10
+ it "should add procs to the before_copy_hooks array when configuring before_copy hooks" do
11
+ @config.before_copy &@proc
12
+ refute_nil @config.before_copy_hook
13
+ end
14
+
15
+ it "should add procs to the after_copy_hooks array when configuring after_copy hooks" do
16
+ @config.after_copy &@proc
17
+ refute_nil @config.after_copy_hook
18
+ end
19
+
20
+ it "should assign to sql_alteration cattr_accessor when configuring sql alteration hook" do
21
+ @config.alter_sql &@proc
22
+ refute_nil @config.sql_alteration
23
+ end
24
+
25
+ after do
26
+ @config.clear
27
+ end
28
+ end
@@ -0,0 +1,39 @@
1
+ require "helper"
2
+
3
+ def copy_machine_db
4
+ ActiveRecord::Base.establish_connection :copy_machine
5
+ yield
6
+ ActiveRecord::Base.establish_connection :test
7
+ end
8
+
9
+ def mock_copy_hook(type)
10
+ Person.expects("#{type}_copy_hook").once
11
+ CopyMachine::Configuration.configure do |config|
12
+ config.send("#{type}_copy") do
13
+ Person.send("#{type}_copy_hook")
14
+ end
15
+ end
16
+ end
17
+
18
+ describe CopyMachine do
19
+ before do
20
+ copy_machine_db { Person.create }
21
+ mock_copy_hook(:before)
22
+ mock_copy_hook(:after)
23
+ end
24
+
25
+ it "should return nil when the copy machine db does not have a record" do
26
+ copy_machine_db { Person.delete_all }
27
+ Person.first.must_equal(nil)
28
+ end
29
+
30
+ it "should return a record when the copy machine db does have a record" do
31
+ refute_nil Person.first
32
+ Person.first # shouldnt fire the copy again
33
+ end
34
+
35
+ after do
36
+ copy_machine_db { Person.delete_all }
37
+ Person.delete_all
38
+ end
39
+ end
data/test/database.yml ADDED
@@ -0,0 +1,7 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+
5
+ copy_machine:
6
+ adapter: sqlite3
7
+ database: ":memory:"
data/test/helper.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup
5
+ require 'minitest/spec'
6
+
7
+ begin
8
+ require 'redgreen'
9
+ rescue LoadError
10
+ end
11
+
12
+ require 'mocha'
13
+
14
+ # Configure Rails
15
+ ENV["RAILS_ENV"] = "test"
16
+
17
+ require 'active_record'
18
+ # require 'active_support'
19
+ # require 'action_controller'
20
+ # require 'active_model'
21
+ # require 'rails/railtie'
22
+ require 'rails'
23
+
24
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
25
+
26
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
27
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
28
+ require 'copy_machine'
29
+
30
+ ActiveRecord::Base.configurations =
31
+ {
32
+ 'test' => {
33
+ 'adapter' => 'mysql',
34
+ 'database' => 'copy_machine_test'
35
+ },
36
+ 'copy_machine' => {
37
+ 'adapter' => 'mysql',
38
+ 'database' => 'copy_machine_slave_test'
39
+ }
40
+ }
41
+
42
+ ActiveRecord::Migration.verbose = false
43
+
44
+ ActiveRecord::Base.send(:include, CopyMachine::ActiveRecordExtensions::Base)
45
+
46
+ class Person < ActiveRecord::Base; end
47
+
48
+ class Migrator
49
+ def self.migrate
50
+ ActiveRecord::Schema.define do
51
+ create_table :people, :force => true do |t|
52
+ t.string :name
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ ActiveRecord::Base.establish_connection :copy_machine
59
+ Migrator.migrate
60
+ ActiveRecord::Base.establish_connection :test
61
+ Migrator.migrate
62
+
63
+ MiniTest::Unit.autorun
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: copy_machine
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Lee Richmond
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-07 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: growl
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: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: minitest
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: For sprawling legacy apps, seeds.rb and fixtures are sometimes not enough. Copy machine eases development by copying records from a slave database as you move through your app, or as you execute predefined templates
50
+ email: richmolj@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - LICENSE
57
+ - README.md
58
+ files:
59
+ - .document
60
+ - .gitignore
61
+ - Gemfile
62
+ - Gemfile.lock
63
+ - LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - VERSION
67
+ - copy_machine.gemspec
68
+ - lib/copy_machine.rb
69
+ - lib/copy_machine/action_controller_extensions/base.rb
70
+ - lib/copy_machine/active_record_extensions/base.rb
71
+ - lib/copy_machine/active_record_extensions/callbacks.rb
72
+ - lib/copy_machine/active_record_extensions/constraints.rb
73
+ - lib/copy_machine/autoloading.rb
74
+ - lib/copy_machine/configuration.rb
75
+ - lib/copy_machine/railtie.rb
76
+ - lib/copy_machine/template.rb
77
+ - lib/generators/copy_machine_configuration_generator.rb
78
+ - lib/generators/copy_machine_template_generator.rb
79
+ - lib/generators/templates/copy_machine.rb
80
+ - lib/generators/templates/example_template.rb
81
+ - lib/rack/copy_machine.rb
82
+ - lib/rack/copy_machine/asset_server.rb
83
+ - lib/rack/copy_machine/public/__rack_copy_machine__/copy_machine.css
84
+ - lib/rack/copy_machine/public/__rack_copy_machine__/copy_machine.js
85
+ - lib/rack/copy_machine/public/__rack_copy_machine__/jquery-1.4.2.min.js
86
+ - lib/rack/views/notifications.html.erb
87
+ - test/configuration_test.rb
88
+ - test/copy_machine_integration_test.rb
89
+ - test/database.yml
90
+ - test/helper.rb
91
+ has_rdoc: true
92
+ homepage: http://github.com/richmolj/copy_machine
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.3.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Easily copy production or slave records into your development database
125
+ test_files:
126
+ - test/configuration_test.rb
127
+ - test/copy_machine_integration_test.rb
128
+ - test/helper.rb