datum 0.8.0 → 0.8.1

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.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Datum is currently under development and pre-1.0
1
+ ##### Datum is currently under development and pre-1.0
2
2
 
3
3
  ## Datum
4
4
 
@@ -12,9 +12,15 @@ Datum is a simple take on Data Driven Testing for Rails. Datum:
12
12
 
13
13
  ## Rails 3
14
14
 
15
- Datum is still in development. Currently, we're working with Rails 3.2.6 and Ruby 1.9.3.
15
+ Datum is still in development. Currently, we're working with Rails 3.2.6 and Ruby 1.9.3.
16
16
 
17
- ### Getting Started
17
+ For now, our target test framework is <b>Test::Unit</b>.
18
+
19
+ ## Getting Started
20
+
21
+ Datum is a simple tool for data driven testing. If you have a test case that you can parameterize and want to manage your parameters via a database, Datum is fun.
22
+
23
+ ### Setting Up
18
24
 
19
25
  Add Datum to your Gemfile:
20
26
 
@@ -32,4 +38,95 @@ rake datum:enable
32
38
 
33
39
  Enable will create several directories in your test directory. It will also prompt you to ask for permission to update your database.yml and application.rb. You MUST review both files even if you have Enable update them for you.
34
40
 
35
- When you are finished, you are ready to add Datum migrations and models to your application as needed.
41
+ Additionally, Enable will further prompt you for permission to verify all core Datum functionality. Verification will include all basic Datum rake tasks along with execution of tests that use Datum's drive_with.
42
+
43
+ <span style="color: red;">WARNING:</span> Enable's verification <b>WILL DROP the Datum Database</b>. If you are re-installing Datum, be sure to back-up your Datum store BEFORE running Enable.
44
+
45
+ When finished, you are ready to create a Datum specific database and add migrations and models.
46
+
47
+ ### Creating a Datum Specific Database and Tables
48
+
49
+ To create a Datum specific database:
50
+
51
+ ```console
52
+ rake datum:db:create
53
+ ```
54
+
55
+ To generate Datum specific migrations and models, the command and options are similar to using Rails scaffolds.
56
+
57
+ ```console
58
+ rails generate datum ModelName column_one:type column_two:type
59
+ ```
60
+
61
+ Models and migrations are placed in your application under test/lib/datum/models and test/lib/datum/migrate. Edit these files as needed. When you are ready to migrate use the Datum migration command.
62
+
63
+ ```console
64
+ rake datum:db:migrate
65
+ ```
66
+
67
+ You are now ready to put data in a newly created table.
68
+
69
+ ### Binding a Test Case to a Table
70
+
71
+ When writing a unit test or functional test with <b>Test::Unit</b>, bind your test case to your table with drive_with.
72
+
73
+ ```ruby
74
+ test "vote_counter should count positive votes" do
75
+ drive_with :table_items
76
+ ```
77
+
78
+ Once bound to your table, drive_with will work with the Datum infrastructure so that your test case will execute once for every row in the table.
79
+
80
+ To access the current row, use the datum accessor:
81
+
82
+ ```ruby
83
+ test "vote_counter should count positive votes" do
84
+ drive_with :table_items
85
+ puts "starting test case..."
86
+ puts "the current id of the row: #{datum.id}"
87
+ ```
88
+
89
+ Will output:
90
+
91
+ ```console
92
+ starting test case...
93
+ 1
94
+
95
+ starting test case...
96
+ 2
97
+
98
+ starting test case...
99
+ 3
100
+ ```
101
+ ### Move Datum Table Data Beyond the Datum Database
102
+
103
+ To convert your Datum tables to fixtures (for storage in scc, etc)
104
+
105
+ ```console
106
+ rake datum:db:dump
107
+ ```
108
+
109
+ To get Datum data from fixtures into the Datum specific database:
110
+
111
+ ```console
112
+ rake datum:db:load
113
+ ```
114
+
115
+ To convert a Datum table into a file so that drive_with does <b>not</b> use the table (and is thus <b>not</b> dependent on a Datum database / settings / etc)
116
+
117
+ ```console
118
+ rake datum:db:localize[table_items]
119
+ ```
120
+
121
+ ## Troubleshooting
122
+
123
+ ### In Development
124
+ Datum is still being created and isn't officially *ready*. It's likely that we have code paths that are not fully tested and some that are plain broken. Stay tuned for a 1.0.
125
+
126
+ ## Additional Information
127
+
128
+ ### Tyemill
129
+ Tyemill is a technology company in Seattle, Washington. We make a few line-of-business applications and love Ruby, Rails and Open Source.
130
+
131
+ ## License
132
+ MIT License. Copyright 2012 Tyemill LLC. http://tyemill.com
data/lib/datum/context.rb CHANGED
@@ -17,9 +17,9 @@ module Datum
17
17
  result = nil if @@table_data.nil?
18
18
  result = @@table_data.delete_at(0) unless @@table_data.nil?
19
19
  @@initialized = false if !result.nil? && @@table_data.count == 0
20
-
20
+
21
21
  log "next row table_data: #{@@table_data}"
22
- log "next row result: #{result.attributes}" unless result.nil?
22
+ #log "next row result: #{result.attributes}" unless result.nil?
23
23
  log "next row initialized: #{@@initialized}"
24
24
  return result
25
25
  end
@@ -1,12 +1,13 @@
1
1
 
2
2
  module Datum
3
+
3
4
  class DbTasks
4
5
  def initialize
5
6
  Rails.env = @@datum_environment
6
7
  end
7
8
 
8
9
  def create
9
- Rake::Task['db:create'].invoke()
10
+ Rake::Task['db:create'].invoke()
10
11
  end
11
12
 
12
13
  def migrate
@@ -73,10 +74,15 @@ module Datum
73
74
  f1.puts "]\nend\nend"
74
75
  end
75
76
  end
76
-
77
+
77
78
  private
78
79
  @@local_path = "#{Rails.root}/test/lib/datum"
80
+
79
81
  @@datum_environment = "datum"
80
82
 
83
+ def context
84
+ return Datum::Context
85
+ end
86
+
81
87
  end
82
88
  end
@@ -38,8 +38,10 @@ module Datum
38
38
  def self.load_model_data table
39
39
  data = nil
40
40
  begin
41
+ log "load_model_data attempting to constantize"
41
42
  driver_method = table.to_s.singularize
42
43
  data = driver_method.classify.constantize.all.reverse
44
+ log "load_model_data data loaded"
43
45
  rescue Exception => exc
44
46
  log "load_model_data: could not get data from model #{driver_method}"
45
47
  log exc
@@ -53,18 +55,50 @@ module Datum
53
55
  def self.load_file_data table
54
56
  data = nil
55
57
  begin
56
- require "lib/datum/locals/#{table}"
57
- cls = driver_method.classify.pluralize.constantize
58
+ driver_method = table.to_s.singularize
59
+ log "load_file_data: attempting require..."
60
+ file = "lib/datum/locals/#{table}"
61
+ klas = driver_method.classify.pluralize
62
+ require file
63
+ log "load_file_data: require was successful"
64
+ cls = klas.constantize
65
+ log "load_file_data: classify pluralize constantize was successful"
58
66
  data = cls::data.reverse
67
+ log "load_file_data: data reading was successful"
59
68
  data = mock_data data
69
+ log "load_file_data: mocking was successful"
60
70
  rescue Exception => exc
61
71
  ## database-driven
62
- log "load_file_data: file load failed. moving to database load."
72
+ log "load_file_data: file load failed for: #{file}"
73
+ log "load_file_data: driver_method: #{driver_method}"
74
+ log "load_file_data: class: #{klas}"
75
+ log "... attempting database connection."
63
76
  end
64
77
 
65
78
  return data
66
79
  end
67
80
 
81
+ def self.mock_data data
82
+ modified_data = []
83
+ data.each_with_index {|e, i|
84
+ o = Object.new
85
+ e.each_pair {|key, value|
86
+ addMockExtension key, value, o
87
+ }
88
+ modified_data.push o
89
+ }
90
+ return modified_data
91
+ end
92
+
93
+ def self.addMockExtension(ext, instance, obj)
94
+ method_name = ext.to_sym
95
+ obj.class.send :define_method, method_name do
96
+ return instance unless instance.to_i.to_s == instance || instance == ""
97
+ return nil if instance == ""
98
+ return instance.to_i
99
+ end
100
+ end
101
+
68
102
  private
69
103
 
70
104
  def self.context
@@ -8,6 +8,9 @@ module Datum
8
8
  notify_check
9
9
  update_yml if @@update_yml
10
10
  update_app if @@update_app
11
+
12
+ (Datum::VerificationTask.new).verify
13
+
11
14
  puts " Datum enabled.\n "
12
15
  end
13
16
 
@@ -46,7 +49,8 @@ module Datum
46
49
  puts "\n>>>>>>>>>>>>>>>> Attempt updates for you? y/n"
47
50
  continue = STDIN.gets.chomp
48
51
  unless continue == 'y' || continue == 'yes'
49
- puts "\n Files must be updated manually to fully enable Datum\n "
52
+ puts "\n Files must be updated manually to fully enable Datum"
53
+ puts " Run rake task 'datum:db:verify' after manual update.\n "
50
54
  exit!
51
55
  end
52
56
  end
@@ -0,0 +1,124 @@
1
+ module Datum
2
+ # some reports of connections / settings issues.
3
+ # verify allows for a full check of the datum db scenarios
4
+ # intended to be used as part of enable to report datum readiness
5
+ class VerificationTask
6
+
7
+ def verify
8
+
9
+ puts "\n### !!!Datum Verification !!!"
10
+ puts "### !!!This command DROPS the Datum Database!!!"
11
+ puts "\n>>>>>>>>>>>>>>>> Proceed with Datum Verification? y/n"
12
+ continue = STDIN.gets.chomp
13
+
14
+ unless continue == 'y' || continue == 'yes'
15
+ puts "\n ... Canceling Datum Verification\n "
16
+ exit!
17
+ end
18
+
19
+ database_ready = false
20
+ database_removed = false
21
+ files_removed = false
22
+
23
+ begin
24
+ dbtsks = DbTasks.new
25
+ puts "\n Verifing Datum functionality...\n "
26
+ dbtsks.create
27
+ puts " >> Database created"
28
+ copy_verification_files
29
+ puts " >> Directories verified\n "
30
+ dbtsks.migrate
31
+ database_ready = true
32
+ puts " >> Migration complete"
33
+ seed_verification_table
34
+ puts " >> Storage verified"
35
+ puts " >> Attempting data driven test cases from database"
36
+ exec_test
37
+ puts " >> Database driven test complete"
38
+ dbtsks.dump
39
+ puts " >> Fixtures generated"
40
+ remove_verification_table_data
41
+ dbtsks.load
42
+ puts " >> Fixture data uploaded"
43
+ dbtsks.localize({:table => "datum_versions"})
44
+ puts " >> Localization complete"
45
+ dbtsks.drop
46
+ database_removed = true
47
+ puts " >> Database dropped"
48
+ puts " >> Attempting data driven test cases from file"
49
+ exec_test
50
+ puts " >> Data file driven test complete"
51
+ remove_verification_files
52
+ files_removed = true
53
+ puts " \n ... Core Datum functionality verified!\n "
54
+ rescue Exception => exc
55
+ puts " >> !!!! Verification failed !!!!"
56
+ puts "#{exc}"
57
+ puts "\n### !!! Please file email datum@tyemill.com with the above output !!!"
58
+ ensure
59
+ remove_verification_table_data if database_ready && !database_removed
60
+ remove_verification_files unless files_removed
61
+ end
62
+ end
63
+
64
+ protected
65
+
66
+ def seed_verification_table
67
+ DatumVersion.create([
68
+ {:version => "0.0.1"},
69
+ {:version => "0.8.0"},
70
+ {:version => "0.8.1"}])
71
+ end
72
+
73
+ def exec_test
74
+ puts " >> Starting data-driven test cases...\n "
75
+ result = system "ruby -Itest #{@@test_src}"
76
+ raise 'Datum Testcases did not complete successfully!' if !result
77
+ puts "\n "
78
+ end
79
+
80
+ def remove_verification_table_data
81
+ DatumVersion.delete_all
82
+ end
83
+
84
+ def copy_verification_files
85
+ FileUtils.cp_r @@migration_src, "#{@@local_path}/migrate"
86
+ FileUtils.cp_r @@model_src, "#{@@local_path}/models"
87
+ FileUtils.cp_r @@test_src, "#{@@unit_dir}"
88
+ end
89
+
90
+ # delete: the migration, the fixture, the ruby file, the model
91
+ def remove_verification_files
92
+ files = ["#{@@local_path}/migrate/#{@@migration_file}",
93
+ "#{@@local_path}/fixtures/#{@@fixture_file}",
94
+ "#{@@local_path}/locals/#{@@ruby_file}",
95
+ "#{@@local_path}/models/#{@@model_file}", @@test_drop]
96
+
97
+ files.each { |file|
98
+ context.log "Removing file: #{file}"
99
+ FileUtils.remove_file file
100
+ }
101
+ end
102
+
103
+ private
104
+ @@local_path = "#{Rails.root}/test/lib/datum"
105
+ @@gem_path = File.expand_path(File.dirname(__FILE__))
106
+ @@migration_file = "20120726105125_create_datum_versions.rb"
107
+ @@version_str = "DatumVersion"
108
+ @@version_tbl = @@version_str.tableize
109
+ @@version_single = @@version_tbl.singularize
110
+ @@model_file = "#{@@version_single}.rb"
111
+ @@fixture_file = "#{@@version_tbl}.yml"
112
+ @@test_file = "#{@@version_single}_test.rb"
113
+ @@ruby_file = "#{@@version_tbl}.rb"
114
+ @@migration_src = "#{@@gem_path}/verify_helpers/#{@@migration_file}"
115
+ @@model_src = "#{@@gem_path}/verify_helpers/#{@@model_file}"
116
+ @@test_src = "#{@@gem_path}/verify_helpers/#{@@test_file}"
117
+ @@unit_dir = "#{Rails.root}/test/unit"
118
+ @@test_drop = "#{@@unit_dir}/#{@@test_file}"
119
+
120
+ def context
121
+ return Datum::Context
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,18 @@
1
+ # used to help verify basic datum functionality
2
+ # see rake datum:db:verify for details
3
+ class CreateDatumVersions < ActiveRecord::Migration
4
+
5
+ ActiveRecord::Base.establish_connection :datum
6
+ ActiveRecord::Base.connection.initialize_schema_migrations_table
7
+
8
+ def self.up
9
+ create_table :datum_versions do |t|
10
+ t.string :version
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :datum_versions
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ # used to help verify basic datum functionality
2
+ # see rake datum:db:verify for details
3
+ class DatumVersion < ActiveRecord::Base
4
+ establish_connection :datum
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+
2
+ # simple test for Datum functionality verification
3
+ require 'test_helper'
4
+
5
+ class DatumVersionTest < ActiveSupport::TestCase
6
+
7
+ test "datum versions should be accessible" do
8
+ drive_with :datum_versions
9
+ str = datum.version
10
+ end
11
+ end
data/lib/datum/version.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  module Datum
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
4
+
5
+ ## Added datum:db:verify to simplify pre-release holes in config
data/lib/datum.rb CHANGED
@@ -23,7 +23,7 @@ module Datum
23
23
  datum_helper::load_data table if !datum_context::initialized?
24
24
  @@driver_row = datum_context.next_row
25
25
  log "drive_with table: #{table}"
26
- log "drive_with row: #{@@driver_row.attributes}" unless @@driver_row.nil?
26
+ #log "drive_with row: #{@@driver_row.attributes}" unless @@driver_row.nil?
27
27
  end
28
28
 
29
29
  def datum
data/lib/tasks/datum.rake CHANGED
@@ -1,4 +1,4 @@
1
-
1
+ require "datum/verification_task"
2
2
  require "datum/enable_task"
3
3
  require "datum/db_tasks"
4
4
 
@@ -25,14 +25,19 @@ namespace :datum do
25
25
 
26
26
  desc "Loads fixtures specific to datum database"
27
27
  task :load do invoke "load" end
28
-
28
+
29
+ #desc "Quick verification of basic datum functionality"
30
+ #task :verify do invoke "verify" end
31
+
29
32
  desc "Enables datum execution without database dependency"
30
33
  task :localize, :table do |t, args|
31
34
  (Datum::DbTasks.new).localize args
32
35
  end
33
36
 
37
+ private
34
38
  def invoke method
35
39
  (Datum::DbTasks.new).send(method)
36
40
  end
41
+
37
42
  end
38
- end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-24 00:00:00.000000000 Z
13
+ date: 2012-07-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70278656633660 !ruby/object:Gem::Requirement
17
+ requirement: &70155510735080 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 3.2.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70278656633660
25
+ version_requirements: *70155510735080
26
26
  description: Flexible data-driven test solution for Rails
27
27
  email:
28
28
  - datum@tyemill.com
@@ -36,6 +36,10 @@ files:
36
36
  - lib/datum/enable_notification.rb
37
37
  - lib/datum/enable_task.rb
38
38
  - lib/datum/railtie.rb
39
+ - lib/datum/verification_task.rb
40
+ - lib/datum/verify_helpers/20120726105125_create_datum_versions.rb
41
+ - lib/datum/verify_helpers/datum_version.rb
42
+ - lib/datum/verify_helpers/datum_version_test.rb
39
43
  - lib/datum/version.rb
40
44
  - lib/datum.rb
41
45
  - lib/generators/datum/datum_generator.rb
@@ -97,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
101
  version: '0'
98
102
  segments:
99
103
  - 0
100
- hash: -2858443151350475509
104
+ hash: 2549513625839685057
101
105
  required_rubygems_version: !ruby/object:Gem::Requirement
102
106
  none: false
103
107
  requirements:
@@ -106,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
110
  version: '0'
107
111
  segments:
108
112
  - 0
109
- hash: -2858443151350475509
113
+ hash: 2549513625839685057
110
114
  requirements: []
111
115
  rubyforge_project:
112
116
  rubygems_version: 1.8.15