Skip to content

Commit

Permalink
Add migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
bluerogue251 committed Apr 27, 2014
1 parent 421e08f commit 5ff785b
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 2 deletions.
Binary file added .Rakefile.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion LICENSE.txt
@@ -1,4 +1,4 @@
Copyright (c) 2014 Teddy
Copyright (c) 2014 Teddy Widom

MIT License

Expand Down
7 changes: 7 additions & 0 deletions Rakefile
@@ -1 +1,8 @@
require "bundler/gem_tasks"
require 'db/migrate/001_create_unmaterialized_clients'
require 'db/migrate/002_create_materialized_clients'

task :migrate do
CreateUnmaterializedClients.new.migrate!
CreateMaterializedClients.new.migrate!
end
16 changes: 16 additions & 0 deletions bin/autospec
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'autospec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rspec-core', 'autospec')
16 changes: 16 additions & 0 deletions bin/htmldiff
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'htmldiff' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('diff-lcs', 'htmldiff')
16 changes: 16 additions & 0 deletions bin/ldiff
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'ldiff' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('diff-lcs', 'ldiff')
16 changes: 16 additions & 0 deletions bin/rake
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rake', 'rake')
16 changes: 16 additions & 0 deletions bin/rspec
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('rspec-core', 'rspec')
7 changes: 7 additions & 0 deletions db/config.yml
@@ -0,0 +1,7 @@
adapter: postgresql
encoding: unicode
host: localhost
pool: 5
username: teddy
password: #
database: materialized_views_test
7 changes: 7 additions & 0 deletions db/migrate/migrate/001_create_unmaterialized_clients.rb
@@ -0,0 +1,7 @@
class CreateUnmaterializedClients < ActiveRecord::Migration
def change
create_table :unmaterialized_clients do |t|
t.string :name
end
end
end
7 changes: 7 additions & 0 deletions db/migrate/migrate/002_create_materialized_clients.rb
@@ -0,0 +1,7 @@
class CreateMaterializedClients < ActiveRecord::Migration
def change
create_table :materialized_clients do |t|
t.string :name
end
end
end
5 changes: 4 additions & 1 deletion materialized_views.gemspec
Expand Up @@ -6,7 +6,7 @@ require 'materialized_views/version'
Gem::Specification.new do |spec|
spec.name = "materialized_views"
spec.version = MaterializedViews::VERSION
spec.authors = ["Teddy"]
spec.authors = ["Teddy Widom"]
spec.email = ["theodore.widom@gmail.com"]
spec.description = %q{TODO: Write a gem description}
spec.summary = %q{TODO: Write a gem summary}
Expand All @@ -20,4 +20,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "activerecord"
spec.add_development_dependency "pg"
end
17 changes: 17 additions & 0 deletions spec/materialized_client_spec.rb
@@ -0,0 +1,17 @@
require 'spec_helper'

class MaterializedClient < ActiveRecord::Base
end

class UnmaterializedClient < ActiveRecord::Base
end

describe MaterializedClient do
describe 'Stays up to date relative its unmaterialized parent' do
specify 'On insertions' do
UnmaterializedClient.create(name: 'new client')
UnmaterializedClient.count.should == 1
MaterializedClient.count.should == 1
end
end
end
13 changes: 13 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,13 @@
require 'materialized_views'
require 'active_record'
require 'yaml'

dbconfig = YAML::load(File.open('db/config.yml'))
ActiveRecord::Base.establish_connection(dbconfig)

RSpec.configure do |config|
config.before(:each) do
UnmaterializedClient.delete_all
MaterializedClient.delete_all
end
end

0 comments on commit 5ff785b

Please sign in to comment.