steamer 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.sw?
2
+ db/*
3
+ *.gem
4
+ .DS_Store
5
+ coverage
6
+ rdoc
7
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Your Name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,44 @@
1
+ Manifesto:
2
+ - create a database for testing that is easily created, is pre-populated with minimal configuration, whose tables are associated correctly, is quickly rolled back between tests, and is correct, every time.
3
+ - should have a way of doing it all by hand but should default to populating the db for you.
4
+ ToDo:
5
+ - Done - get it working with sqlite3
6
+ - Done - read in all models
7
+ - record attribute information in a test db
8
+ - need a method to open the database
9
+ - need a method to create/write to the database table generic data
10
+ - record association information
11
+ - for each association (habtm, has_many, has_one, belongs_to, etc.),
12
+ - if it uses a join table, or is owned/owns another model
13
+ - find the join table, or child table
14
+ - make sure id's and foreign keys line up.
15
+ - write it to the database with a function call?
16
+ - reset the database with a function call?
17
+ - drop the database with a function call?
18
+
19
+ Discussion:
20
+ Maybe I can use populator and faker to add data to the database...
21
+
22
+ There are definitely a couple of different ways I can go with this:
23
+ one, I can create the factory files via meta programming, and have them loaded as usual using begin-end block in env.rb (slow but db agnostic)
24
+ two, I can create the database from scratch and roll it back somehow whenever you tell it to roll back (faster but need to know the database)
25
+ three, I can somehow get into the model instances that are created in the development environment...not sure how to do this from 'RAILS_ENV=test'
26
+ four, I can use ActiveRecord::Base class methods to record attributes and associations of the db tables (i.e. reflect_on_association), and then create the test database on the fly whenever needed. (this sounds like the best solution, so I can completely forget about factory_girl, and I am not reinventing the activerecord wheel by trying to parse model files, yet I am properly recording my associations, creating the test database correctly, and reusing it as many times as I want) (maybe there's a formal rollback method for the test database connection, I think I saw one...) (lets just hope I can use all of the AR class methods from the test env when needed. Update: yes!!! Even without tables created and filled out w/AR, I can use class methods to study/use associations and attributes...fantastic)
27
+
28
+ - May want to read from the models... that way, we can stay db agnostic...
29
+ - can we use reflect_on_association??? is this too hard?
30
+ - how can we structure this so that it makes sense? are we replicating effort?
31
+ - we could require the model files, create instances in memory without writing to the db, then when we have to, write to the test db.
32
+ - want to have it in memory the way you want it, and write to the db at each iteration instead of recreating the database manually.
33
+ - we should stay away from the database itself until we write it... to the test db at each interval
34
+ - get it working with cucumber first...
35
+ - construct the data automatically, minimal effort to construct factories yall...
36
+ - the instances should be created with restrictions in mind
37
+ - should Steamer be of type ActiveRecord::Base to take advantage of reflect on association?
38
+ - read from database
39
+ - write it to factory directory in rb files
40
+ - instantiate it correctly in env.rb or wherever the factories are normally created (cucumber, rspec, etc.)
41
+ - get associations made correctly using model associations
42
+ - test out the factories
43
+ - write some specs
44
+ - we want to have a version of the database that we can go back to...
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = steamer
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Your Name. See LICENSE for details.
data/README2 ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,133 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "steamer"
8
+ #gem.executables = "steamer"
9
+ gem.summary = %Q{when you want to dup a db for use in factories without the hassle of creating factories by hand}
10
+ gem.email = "david.t.rogers@gmail.com"
11
+ gem.homepage = "http://github.com/davidtrogers/steamer"
12
+ gem.authors = ["Dave Rogers"]
13
+ # gem.version = "#{version}.#{Time.now.to_i}"
14
+ gem.rdoc_options = ["--inline-source", "--charset=UTF-8"]
15
+ gem.require_paths = ["lib"]
16
+ gem.rubygems_version = %q{1.3.3}
17
+ gem.add_dependency "activerecord"
18
+ # puts "version: #{version}.#{Time.now.to_i}"
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ # if s.respond_to? :specification_version then
21
+ # current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ # s.specification_version = 2
23
+ # if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
24
+ # else
25
+ # end
26
+ # else
27
+ # end
28
+ end
29
+
30
+ Jeweler::GemcutterTasks.new
31
+ rescue LoadError
32
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
33
+ end
34
+
35
+ #
36
+ # -*- encoding: utf-8 -*-
37
+
38
+ # Gem::Specification.new do |s|
39
+ # s.name = %q{davidtrogers-grit}
40
+ # s.version = "0.4.4"
41
+ #
42
+ # s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
43
+ # s.authors = ["brynary"]
44
+ # s.date = %q{2009-03-31}
45
+ # s.description = %q{"webrat is awesome"}
46
+ # s.email = %q{david.t.rogers@gmail.com}
47
+ # s.homepage = %q{http://github.com/davidtrogers/webrat}
48
+ # s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
49
+ # s.require_paths = ["lib"]
50
+ # s.rubyforge_project = %q{webrat}
51
+ # s.rubygems_version = %q{1.3.3}
52
+ # s.summary = %q{Webrat is awesome}
53
+ #
54
+ # if s.respond_to? :specification_version then
55
+ # current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ # s.specification_version = 2
57
+ #
58
+ # if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ # else
60
+ # end
61
+ # else
62
+ # end
63
+ # end
64
+
65
+
66
+ # begin
67
+ # require 'jeweler'
68
+ # Jeweler::Tasks.new do |s|
69
+ # s.name = "jeweler"
70
+ # s.executables = "jeweler"
71
+ # s.summary = "Simple and opinionated helper for creating Rubygem projects on GitHub"
72
+ # s.email = "josh@technicalpickles.com"
73
+ # s.homepage = "http://github.com/technicalpickles/jeweler"
74
+ # s.description = "Simple and opinionated helper for creating Rubygem projects on GitHub"
75
+ # s.authors = ["Josh Nichols"]
76
+ # s.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore']
77
+ # s.add_dependency 'schacon-git'
78
+ # end
79
+ # rescue LoadError
80
+ # puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
81
+ # end
82
+ #
83
+
84
+
85
+ # Gem::Specification.new do |s|
86
+ # s.name = "amee"
87
+ # s.version = "2.0.16"
88
+ # s.date = "2009-05-12"
89
+ # s.summary = "Ruby interface to the AMEE carbon calculator"
90
+ # s.email = "james@floppy.org.uk"
91
+ # s.homepage = "http://github.com/Floppy/amee-ruby"
92
+ # s.has_rdoc = true
93
+ # s.authors = ["James Smith"]
94
+ # s.files = ["README", "COPYING"]
95
+ # s.files += ['lib/amee.rb', 'lib/amee/connection.rb', 'lib/amee/data_item.rb', 'lib/amee/exceptions.rb', 'lib/amee/profile.rb', 'lib/amee/profile_object.rb', 'lib/amee/profile_category.rb', 'lib/amee/profile_item.rb', 'lib/amee/profile_item_value.rb', 'lib/amee/version.rb', 'lib/amee/data_category.rb', 'lib/amee/data_item_value.rb', 'lib/amee/data_object.rb', 'lib/amee/object.rb', 'lib/amee/shell.rb', 'lib/amee/drill_down.rb', 'lib/amee/rails.rb', 'lib/amee/pager.rb', 'lib/amee/item_definition.rb']
96
+ # s.files += ['bin/ameesh']
97
+ # s.files += ['examples/list_profiles.rb', 'examples/create_profile.rb', 'examples/create_profile_item.rb', 'examples/view_data_category.rb', 'examples/view_data_item.rb']
98
+ # s.files += ['init.rb', 'rails/init.rb']
99
+ # s.executables = ['ameesh']
100
+ # s.add_dependency("activesupport")
101
+ # s.add_dependency("json")
102
+ # end
103
+
104
+ require 'spec/rake/spectask'
105
+ Spec::Rake::SpecTask.new(:spec) do |spec|
106
+ spec.libs << 'lib' << 'spec'
107
+ spec.spec_files = FileList['spec/**/*_spec.rb']
108
+ end
109
+
110
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
111
+ spec.libs << 'lib' << 'spec'
112
+ spec.pattern = 'spec/**/*_spec.rb'
113
+ spec.rcov = true
114
+ end
115
+
116
+
117
+ task :default => :spec
118
+
119
+ require 'rake/rdoctask'
120
+ Rake::RDocTask.new do |rdoc|
121
+ if File.exist?('VERSION.yml')
122
+ config = YAML.load(File.read('VERSION.yml'))
123
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
124
+ else
125
+ version = ""
126
+ end
127
+
128
+ rdoc.rdoc_dir = 'rdoc'
129
+ rdoc.title = "steamer #{version}"
130
+ rdoc.rdoc_files.include('README*')
131
+ rdoc.rdoc_files.include('lib/**/*.rb')
132
+ end
133
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
data/lib/steamer.rb ADDED
@@ -0,0 +1,108 @@
1
+ require 'activerecord'
2
+ require 'sqlite3'
3
+
4
+ class Steamer
5
+
6
+ attr_accessor :source_db_connection,
7
+ :source_db, :models,
8
+ :model_files,
9
+ :model_reflections
10
+
11
+ def initialize
12
+ connect
13
+ end
14
+
15
+ def connect # assuming sqlite3 db at the moment
16
+ @source_db_name = Dir[File.join("./*/development.sqlite3")].first
17
+ @destination_db_name = Dir[File.join("./*/test.sqlite3")].first
18
+ # read from sqlite3 db
19
+ @source_db= ActiveRecord::Base.establish_connection({:adapter => "sqlite3",
20
+ :database => @source_db_name})
21
+ @source_db_connection = @source_db.connection
22
+ @source_db.connected?
23
+ end
24
+
25
+ def setup_models
26
+ # get all of the models, store in an Array
27
+ @models = []
28
+
29
+ Kernel.subclasses_of(ActiveRecord::Base).each do |cl|
30
+ if !cl.to_s.include?('ActiveRecord')
31
+ @models.push cl
32
+ end
33
+ end
34
+
35
+ ## now I have all the models by name... construct a datastructure to hold them all
36
+ ## once that is done, I can write them to the database...
37
+ @model_reflections = {}
38
+ begin
39
+ @models.each do |model|
40
+ # if (Kernel.subclasses_of(ActiveRecord::Base).member?(model))
41
+ @model_reflections[:model] = eval("#{model}.reflections")
42
+ # end
43
+ end
44
+ rescue NameError => msg
45
+ puts "sorry, #{msg}"
46
+ end
47
+ end
48
+
49
+ def write_all_tables
50
+ # for each table write_table(table)
51
+
52
+ # write associations to the tables (i.e. the foreign keys)
53
+ end
54
+
55
+ def write_table(table) # protected?
56
+ # locate the model in @models
57
+
58
+ # get a connection to the table
59
+
60
+ # write to the table based on its types
61
+ end
62
+
63
+ def reset_tables
64
+ # drop all tables,
65
+
66
+ # write_all_tables
67
+ end
68
+
69
+ def get_model_files(root_dir = "./app/models/*")
70
+ temp_arr = []
71
+ Dir[File.join(root_dir)].each do |tok|
72
+ if File.directory?(tok)
73
+ temp_arr = temp_arr + get_model_files(tok.concat("/*"))
74
+ else
75
+ temp_arr.push tok
76
+ end
77
+ end
78
+ return temp_arr
79
+ end
80
+
81
+ end
82
+
83
+
84
+ # This shows the columns for a particular table
85
+ # >> puts s.source_db_connection.columns("work_efforts").each {|a| puts a.inspect}
86
+
87
+ # This shows all of the tables
88
+ # >> puts s.source_db_connection.tables
89
+
90
+ # This returns a hash of the table structure
91
+ # >> puts s.source_db_connection.table_structure("work_efforts")
92
+
93
+ #TRASH code
94
+ # @model_files = get_model_files #Dir[File.join(RAILS_ROOT + "/app/models/*/*")]
95
+
96
+ ## for each one, get file name
97
+ ##@models.push File.basename(file,"*.rb").camelize
98
+ #@model_files.each do |file|
99
+ # file.sub!("./app/models/","")
100
+ # if file.split("/").size>1
101
+ # @models.push "#{file.split('/')[0].camelize}::#{file.split('/')[1].camelize.chomp(".rb")}"
102
+ # else
103
+ # @models.push file.camelize.chomp(".rb")
104
+ # end
105
+ #end
106
+ # Kernel.subclasses_of(ActiveRecord::Base).to_s.include?('user'.camelize)
107
+
108
+ # s.models.each {|a| if Kernel.const_defined?(a); puts a; else puts "couldnt find #{a}; end"}
data/loremipsum.txt ADDED
@@ -0,0 +1 @@
1
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus mollis sapien a massa commodo interdum. Quisque auctor commodo placerat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non metus orci. Morbi varius eros eu justo venenatis eget consectetur diam sodales. Integer quis nisl sem, vel auctor neque. Praesent nec neque quis magna sodales consequat. Quisque augue tortor, ullamcorper eu interdum elementum, luctus sed quam. Sed id eros neque. Morbi nec ligula in orci ultrices ultrices ac et metus. Integer volutpat cursus nisi, at molestie orci suscipit tempor. Curabitur lobortis imperdiet tellus vel ultricies. Aenean quis mi orci, ac tincidunt lorem. Aliquam id lectus nec lacus gravida feugiat eu convallis ipsum. Mauris aliquet blandit consectetur.
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'steamer'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Steamer" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/steamer.gemspec ADDED
@@ -0,0 +1,58 @@
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{steamer}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dave Rogers"]
12
+ s.date = %q{2010-02-16}
13
+ s.email = %q{david.t.rogers@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README",
17
+ "README.rdoc",
18
+ "README2"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README",
25
+ "README.rdoc",
26
+ "README2",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/steamer.rb",
30
+ "loremipsum.txt",
31
+ "spec/spec_helper.rb",
32
+ "spec/steamer_spec.rb",
33
+ "steamer.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/davidtrogers/steamer}
36
+ s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.5}
39
+ s.summary = %q{when you want to dup a db for use in factories without the hassle of creating factories by hand}
40
+ s.test_files = [
41
+ "spec/spec_helper.rb",
42
+ "spec/steamer_spec.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<activerecord>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<activerecord>, [">= 0"])
56
+ end
57
+ end
58
+
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steamer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Dave Rogers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-16 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: david.t.rogers@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README
34
+ - README.rdoc
35
+ - README2
36
+ files:
37
+ - .document
38
+ - .gitignore
39
+ - LICENSE
40
+ - README
41
+ - README.rdoc
42
+ - README2
43
+ - Rakefile
44
+ - VERSION
45
+ - lib/steamer.rb
46
+ - loremipsum.txt
47
+ - spec/spec_helper.rb
48
+ - spec/steamer_spec.rb
49
+ - steamer.gemspec
50
+ has_rdoc: true
51
+ homepage: http://github.com/davidtrogers/steamer
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --inline-source
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: when you want to dup a db for use in factories without the hassle of creating factories by hand
79
+ test_files:
80
+ - spec/spec_helper.rb
81
+ - spec/steamer_spec.rb