jtrupiano-story-helper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 0.1.0 / 2008-09-16
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/storify
6
+ lib/story-helper.rb
7
+ lib/story-helper/conf/story_accessors.rb
8
+ lib/story-helper/conf/story_helper.rake
9
+ lib/story-helper/conf/story_helper.rb
10
+ lib/story-helper/version.rb
11
+ story-helper.gemspec
12
+ test/rails_version_test.rb
13
+ test/test_story_helper.rb
@@ -0,0 +1,48 @@
1
+ = story-helper
2
+
3
+ * http://github.com/jtrupiano/story-helper
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 FIX
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/story-helper.rb'
6
+ require './lib/story-helper/version'
7
+
8
+ PKG_NAME = "story-helper"
9
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
10
+ version = StoryHelper::Version::STRING.dup
11
+ if ENV['SNAPSHOT'].to_i == 1
12
+ version << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
13
+ end
14
+ PKG_VERSION = version
15
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
16
+
17
+ Hoe.new(PKG_NAME, PKG_VERSION) do |p|
18
+ p.rubyforge_name = 'johntrupiano' # if different than lowercase project name
19
+ p.developer('John Trupiano', 'jtrupiano@gmail.com')
20
+ p.name = PKG_NAME
21
+ p.version = PKG_VERSION
22
+ #p.platform = Gem::Platform::RUBY
23
+ p.description = %q(A set of helpers/features to aid in implementing the StoryHelper concept in rails apps)
24
+ p.summary = p.description # More details later??
25
+ p.remote_rdoc_dir = PKG_NAME # Release to /PKG_NAME
26
+ # p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n")
27
+ p.need_zip = true
28
+ p.need_tar = false
29
+ end
30
+
31
+ # vim: syntax=Ruby
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # storify
3
+ # Author: John Trupiano
4
+ #
5
+ # Steps
6
+ # 1) Check if lib/story_helper.rb exists-- if not, let's place it in there
7
+ # 2) Check if lib/story_accessors.rb exists-- if not, let's place it in there
8
+ # 3) Check if lib/tasks/story_helper.rake exists-- if not, let's place it in there
9
+ # 4) Tell them to update their test_helper.rb file
10
+ #
11
+ # 5) How else can we help the user out?
12
+ # Can we auto-convert their fixtures?
13
+ # How about creating default StoryAccessors sections for each model?
14
+ # What else??
15
+
16
+ require 'fileutils'
17
+ include FileUtils
18
+
19
+ #require 'yaml'
20
+
21
+ class Storify
22
+
23
+ def self.run!
24
+ rails_root = ARGV[0] || '.'
25
+ puts "rails_root: #{rails_root}"
26
+ config_base = File.join(rails_root, 'config')
27
+ old_env_dir = File.join(config_base, 'environments')
28
+
29
+ # lib/story_helper.rb
30
+ story_helper_rb = File.join(rails_root, 'lib', 'story_helper.rb')
31
+ gem_story_helper_rb = File.dirname(__FILE__) + '/../lib/conf/story_helper.rb'
32
+ copy_if_missing(gem_story_helper_rb, story_helper_rb)
33
+
34
+ # lib/story_accessors.rb
35
+ story_accessors_rb = File.join(rails_root, 'lib', 'story_accessors.rb')
36
+ gem_story_accessors_rb = File.dirname(__FILE__) + '/../lib/conf/story_accessors.rb'
37
+ copy_if_missing(gem_story_accessors_rb, story_accessors_rb)
38
+
39
+ # lib/tasks/story_helper.rake
40
+ story_helper_rake = File.join(rails_root, 'lib', 'tasks', 'story_helper.rake')
41
+ gem_story_helper_rake = File.dirname(__FILE__) + '/../lib/conf/story_helper.rake'
42
+ copy_if_missing(gem_story_helper_rake, story_helper_rake)
43
+ end
44
+
45
+ private
46
+ def self.copy_if_missing(from, to)
47
+ if !File.exists?(from)
48
+ puts "cp #{from} #{to}"
49
+ cp(from, to)
50
+ else
51
+ puts "#{to} already exists"
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ Storify.run!
58
+ puts "Don't forget to include StoryAccessors::Methods into your test_helper."
File without changes
@@ -0,0 +1,42 @@
1
+
2
+ module StoryAccessors
3
+
4
+ module Methods
5
+
6
+ ####### Accounts #######
7
+ # %w(amy sarah joanne julia erin).each do |acct|
8
+ # meta_accessor(acct.to_s, Account, "login")
9
+ # end
10
+
11
+
12
+ end
13
+
14
+ end
15
+
16
+
17
+
18
+ # Defines a basic cached accessor
19
+ def meta_accessor(accessor, klass, find_by_field="name", field_value=accessor)
20
+ src = <<-RUBY
21
+ def #{accessor}(reload=false)
22
+ return @#{accessor} if @#{accessor} && !reload
23
+ @#{accessor} = #{klass.to_s}.find_by_#{find_by_field}("#{field_value}")
24
+ end
25
+ RUBY
26
+ class_eval src, __FILE__, __LINE__
27
+ end
28
+
29
+ # Generalized accessor functor
30
+ def scoped_meta_accessor(model_str, key, value, scoped_type, scoped_type_id, default_accessor_str)
31
+ scoped_field = "#{scoped_type}_id"
32
+ src = <<-RUBY
33
+ def #{key}(#{scoped_type}=#{default_accessor_str}, reload=false)
34
+ key = "@#{key}_" + #{scoped_type}.#{scoped_type_id}.to_s.gsub(' ', '_')
35
+ if reload || !instance_variable_defined?(key.to_sym)
36
+ instance_variable_set(key.to_sym, #{model_str}.find_by_name_and_#{scoped_field}(%q(#{value}), #{scoped_type}.id))
37
+ end
38
+ instance_variable_get(key.to_sym)
39
+ end
40
+ RUBY
41
+ class_eval src, __FILE__, __LINE__
42
+ end
@@ -0,0 +1,43 @@
1
+ #############################
2
+ # Rewrites the test tasks to enforce StoryHelper usage
3
+ #############################
4
+
5
+ namespace :db do
6
+ desc "Load dev data into the current environment's database."
7
+ task :load_stories => :environment do
8
+ StoryHelper.purge_all_data
9
+ StoryHelper.load_all
10
+ end
11
+ end
12
+
13
+ # First, delete the Tasks we wish to override
14
+ ["functionals", "units", "integrations", "all"].each do |tt|
15
+ Rake.application.send(:eval, "@tasks.delete('test:#{tt}')")
16
+ end
17
+
18
+ # Now, override them!
19
+ namespace :test do
20
+ Rake::TestTask.new(:units) do |t|
21
+ t.libs << "test"
22
+ t.pattern = 'test/unit/**/*_test.rb'
23
+ t.verbose = true
24
+ end
25
+ Rake::Task['test:units'].comment = "*StoryHelper: Run the unit tests in test/unit. Your test data MUST be preloaded into the database."
26
+
27
+ Rake::TestTask.new(:functionals) do |t|
28
+ t.libs << "test"
29
+ t.pattern = 'test/functional/**/*_test.rb'
30
+ t.verbose = true
31
+ end
32
+ Rake::Task['test:functionals'].comment = "StoryHelper: Run the functional tests in test/functional. Your test data MUST be preloaded into the database."
33
+
34
+ Rake::TestTask.new(:integrations) do |t|
35
+ t.libs << "test"
36
+ t.pattern = 'test/integration/**/*_test.rb'
37
+ t.verbose = true
38
+ end
39
+ Rake::Task['test:integrations'].comment = "StoryHelper: Run the integration tests in test/integration. Your test data MUST be preloaded into the database."
40
+
41
+ desc "StoryHelper: Run unit and functional tests. Your test data MUST be preloaded into the database."
42
+ task :all => [:units, :functionals, :integrations]
43
+ end
@@ -0,0 +1,17 @@
1
+ # Exposes methods that create dev and test data. Loads things from a "user story"
2
+ # perspective.
3
+ class StoryHelper
4
+ self.extend StoryAccessors::Methods
5
+
6
+ def self.load_all
7
+ # Load data via Ruby -- your models are accessible here, so use those functions to create complex data!
8
+
9
+ end
10
+
11
+ #
12
+ def self.purge_all_data
13
+ # Manually delete from all models and non-model join tables
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,20 @@
1
+ module StoryHelper
2
+ module Version #:nodoc:
3
+ # A method for comparing versions of required modules. It expects two
4
+ # arrays of integers as parameters, the first being the minimum version
5
+ # required, and the second being the actual version available. It returns
6
+ # true if the actual version is at least equal to the required version.
7
+ def self.check(required, actual) #:nodoc:
8
+ required = required.map { |v| "%06d" % v }.join(".")
9
+ actual = actual.map { |v| "%06d" % v }.join(".")
10
+ return actual >= required
11
+ end
12
+
13
+ MAJOR = 0
14
+ MINOR = 1
15
+ TINY = 0
16
+
17
+ STRING = [MAJOR, MINOR, TINY].join(".")
18
+ end
19
+ end
20
+
@@ -0,0 +1,35 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{story-helper}
3
+ s.version = "0.1.0"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["John Trupiano"]
7
+ s.date = %q{2008-09-16}
8
+ s.default_executable = %q{storify}
9
+ s.description = %q{A set of helpers/features to aid in implementing the StoryHelper concept in rails apps}
10
+ s.email = ["jtrupiano@gmail.com"]
11
+ s.executables = ["storify"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/storify", "lib/story-helper.rb", "lib/story-helper/conf/story_accessors.rb", "lib/story-helper/conf/story_helper.rake", "lib/story-helper/conf/story_helper.rb", "lib/story-helper/version.rb", "story-helper.gemspec", "test/rails_version_test.rb", "test/test_story_helper.rb"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/jtrupiano/story-helper}
16
+ s.rdoc_options = ["--main", "README.txt"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{johntrupiano}
19
+ s.rubygems_version = %q{1.2.0}
20
+ s.summary = %q{A set of helpers/features to aid in implementing the StoryHelper concept in rails apps}
21
+ s.test_files = ["test/test_story_helper.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if current_version >= 3 then
28
+ s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
29
+ else
30
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+ require 'yaml'
4
+
5
+ class RailsVersionTest < Test::Unit::TestCase
6
+ include FileUtils
7
+
8
+ def test_rails_two_one_one
9
+ # Clean up an old run if necessary
10
+ rm_rf('rails211test')
11
+
12
+ cp_r('rails211', 'rails211test')
13
+ system("storify rails211test")
14
+
15
+ # config_root = File.join('rails211test', 'config')
16
+ #
17
+ # assert File.exists?(File.join(config_root, 'postboot.rb'))
18
+ #
19
+ # env_rb = File.open(File.join(config_root, 'environment.rb')).read
20
+ # assert env_rb.include?("require File.join(File.dirname(__FILE__), 'postboot')")
21
+ #
22
+ # %w(development test demo staging production).each do |env|
23
+ # assert File.directory?(File.join(config_root, env))
24
+ # end
25
+ #
26
+ # %w(development test production).each do |env|
27
+ # %w(database.yml environment.rb).each do |f|
28
+ # assert File.exists?(File.join(config_root, env, f))
29
+ # end
30
+ # puts "Testing #{env}"
31
+ # y = YAML.load_file(File.join(config_root, env, 'database.yml'))
32
+ # assert_equal 1, y.keys.size
33
+ # assert_equal env, y.keys.first
34
+ # end
35
+ # ensure
36
+ # rm_rf('rails210test')
37
+ end
38
+ end
File without changes
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jtrupiano-story-helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Trupiano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-09-16 00:00:00 -07:00
13
+ default_executable: storify
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.7.0
23
+ version:
24
+ description: A set of helpers/features to aid in implementing the StoryHelper concept in rails apps
25
+ email:
26
+ - jtrupiano@gmail.com
27
+ executables:
28
+ - storify
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - bin/storify
41
+ - lib/story-helper.rb
42
+ - lib/story-helper/conf/story_accessors.rb
43
+ - lib/story-helper/conf/story_helper.rake
44
+ - lib/story-helper/conf/story_helper.rb
45
+ - lib/story-helper/version.rb
46
+ - story-helper.gemspec
47
+ - test/rails_version_test.rb
48
+ - test/test_story_helper.rb
49
+ has_rdoc: true
50
+ homepage: http://github.com/jtrupiano/story-helper
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --main
54
+ - README.txt
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project: johntrupiano
72
+ rubygems_version: 1.2.0
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: A set of helpers/features to aid in implementing the StoryHelper concept in rails apps
76
+ test_files:
77
+ - test/test_story_helper.rb