jtrupiano-story-helper 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +2 -2
- data/Manifest.txt +2 -1
- data/{README.txt → README.textile} +22 -12
- data/bin/storify +38 -9
- data/lib/story-helper/conf/story_accessors.rb +13 -17
- data/lib/story-helper/conf/story_helper.rake +41 -5
- data/lib/story-helper/conf/story_helper.rb +45 -7
- data/lib/story-helper/conf/test_helper_extensions.rb +44 -0
- data/lib/story-helper/version.rb +1 -1
- data/story-helper.gemspec +11 -10
- metadata +6 -6
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
History.txt
|
2
2
|
Manifest.txt
|
3
|
-
README.
|
3
|
+
README.textile
|
4
4
|
Rakefile
|
5
5
|
bin/storify
|
6
6
|
lib/story-helper.rb
|
7
7
|
lib/story-helper/conf/story_accessors.rb
|
8
8
|
lib/story-helper/conf/story_helper.rake
|
9
9
|
lib/story-helper/conf/story_helper.rb
|
10
|
+
lib/story-helper/conf/test_helper_extensions.rb
|
10
11
|
lib/story-helper/version.rb
|
11
12
|
story-helper.gemspec
|
12
13
|
test/rails_version_test.rb
|
@@ -1,28 +1,38 @@
|
|
1
|
-
|
1
|
+
h1. story-helper
|
2
2
|
|
3
|
-
|
3
|
+
p. http://github.com/jtrupiano/story-helper
|
4
4
|
|
5
|
-
|
5
|
+
h2. DESCRIPTION
|
6
6
|
|
7
|
-
|
7
|
+
p. Provides very basic baseline for using direct Ruby to define your test data and test accessors. Still a work in progress,
|
8
|
+
but something we use at SLS in lieu of fixtures. More details to come as this becomes more useful to others.
|
8
9
|
|
9
|
-
|
10
|
+
p. There's some information on the wiki regarding how to use it in conjunction with fixtures.
|
10
11
|
|
11
|
-
|
12
|
+
h2. FEATURES/PROBLEMS
|
12
13
|
|
13
|
-
|
14
|
+
* not entirely DRY (requires you to define your accessors in addition to your test data -- this should be able to be automated)
|
15
|
+
* could auto-convert existing fixtures
|
16
|
+
* should only be used in conjunction with pre-built test databases (in other words, no dropping and recreating for each test case -- use DB transactions instead)
|
14
17
|
|
15
|
-
|
18
|
+
h2. SYNOPSIS
|
16
19
|
|
17
|
-
|
20
|
+
from RAILS_ROOT
|
21
|
+
* storify .
|
22
|
+
|
23
|
+
Implement StoryHelper#purge_all_data and StoryHelper#load_all in lib/story_helper.rb
|
24
|
+
* rake db:stories:load RAILS_ENV=____
|
25
|
+
|
26
|
+
h2. REQUIREMENTS
|
18
27
|
|
19
28
|
* FIX (list of requirements)
|
20
29
|
|
21
|
-
|
30
|
+
h2. INSTALL
|
22
31
|
|
23
|
-
*
|
32
|
+
* sudo gem install story-helper (stable version from RubyForge)
|
33
|
+
* sudo gem install jtrupiano-story-helper (HEAD of the repo from github)
|
24
34
|
|
25
|
-
|
35
|
+
h2. LICENSE
|
26
36
|
|
27
37
|
(The MIT License)
|
28
38
|
|
data/bin/storify
CHANGED
@@ -23,28 +23,43 @@ class Storify
|
|
23
23
|
def self.run!
|
24
24
|
rails_root = ARGV[0] || '.'
|
25
25
|
puts "rails_root: #{rails_root}"
|
26
|
-
|
27
|
-
old_env_dir = File.join(config_base, 'environments')
|
28
|
-
|
26
|
+
|
29
27
|
# lib/story_helper.rb
|
30
28
|
story_helper_rb = File.join(rails_root, 'lib', 'story_helper.rb')
|
31
|
-
gem_story_helper_rb = File.dirname(__FILE__) + '/../lib/conf/story_helper.rb'
|
29
|
+
gem_story_helper_rb = File.dirname(__FILE__) + '/../lib/story-helper/conf/story_helper.rb'
|
32
30
|
copy_if_missing(gem_story_helper_rb, story_helper_rb)
|
33
31
|
|
34
32
|
# lib/story_accessors.rb
|
35
33
|
story_accessors_rb = File.join(rails_root, 'lib', 'story_accessors.rb')
|
36
|
-
gem_story_accessors_rb = File.dirname(__FILE__) + '/../lib/conf/story_accessors.rb'
|
34
|
+
gem_story_accessors_rb = File.dirname(__FILE__) + '/../lib/story-helper/conf/story_accessors.rb'
|
37
35
|
copy_if_missing(gem_story_accessors_rb, story_accessors_rb)
|
38
36
|
|
39
37
|
# lib/tasks/story_helper.rake
|
40
38
|
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'
|
39
|
+
gem_story_helper_rake = File.dirname(__FILE__) + '/../lib/story-helper/conf/story_helper.rake'
|
42
40
|
copy_if_missing(gem_story_helper_rake, story_helper_rake)
|
43
41
|
end
|
44
42
|
|
43
|
+
def self.cleanup!
|
44
|
+
rails_root = ARGV[0] || '.'
|
45
|
+
puts "rails_root: #{rails_root}"
|
46
|
+
|
47
|
+
# lib/story_helper.rb
|
48
|
+
story_helper_rb = File.join(rails_root, 'lib', 'story_helper.rb')
|
49
|
+
delete_unless_missing(story_helper_rb)
|
50
|
+
|
51
|
+
# lib/story_accessors.rb
|
52
|
+
story_accessors_rb = File.join(rails_root, 'lib', 'story_accessors.rb')
|
53
|
+
delete_unless_missing(story_accessors_rb)
|
54
|
+
|
55
|
+
# lib/tasks/story_helper.rake
|
56
|
+
story_helper_rake = File.join(rails_root, 'lib', 'tasks', 'story_helper.rake')
|
57
|
+
delete_unless_missing(story_helper_rake)
|
58
|
+
end
|
59
|
+
|
45
60
|
private
|
46
61
|
def self.copy_if_missing(from, to)
|
47
|
-
if !File.exists?(
|
62
|
+
if !File.exists?(to)
|
48
63
|
puts "cp #{from} #{to}"
|
49
64
|
cp(from, to)
|
50
65
|
else
|
@@ -52,7 +67,21 @@ class Storify
|
|
52
67
|
end
|
53
68
|
end
|
54
69
|
|
70
|
+
def self.delete_unless_missing(file)
|
71
|
+
if File.exists?(file)
|
72
|
+
cmd = "rm #{file}"
|
73
|
+
puts cmd
|
74
|
+
rm_f(file)
|
75
|
+
else
|
76
|
+
puts "Deleting #{file}....doesn't exist."
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
55
80
|
end
|
56
81
|
|
57
|
-
|
58
|
-
|
82
|
+
if ARGV.size > 1 && ARGV[1] == "cleanup"
|
83
|
+
Storify.cleanup!
|
84
|
+
else
|
85
|
+
Storify.run!
|
86
|
+
puts "Don't forget to include StoryAccessors::Methods into your test_helper."
|
87
|
+
end
|
@@ -1,20 +1,3 @@
|
|
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
1
|
# Defines a basic cached accessor
|
19
2
|
def meta_accessor(accessor, klass, find_by_field="name", field_value=accessor)
|
20
3
|
src = <<-RUBY
|
@@ -40,3 +23,16 @@ def scoped_meta_accessor(model_str, key, value, scoped_type, scoped_type_id, def
|
|
40
23
|
RUBY
|
41
24
|
class_eval src, __FILE__, __LINE__
|
42
25
|
end
|
26
|
+
|
27
|
+
module StoryAccessors
|
28
|
+
|
29
|
+
module Methods
|
30
|
+
|
31
|
+
####### Accounts #######
|
32
|
+
# %w(amy sarah joanne julia erin).each do |acct|
|
33
|
+
# meta_accessor(acct.to_s, Account, "login")
|
34
|
+
# end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -3,11 +3,47 @@
|
|
3
3
|
#############################
|
4
4
|
|
5
5
|
namespace :db do
|
6
|
-
desc "
|
7
|
-
task :
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
desc "Refresh all the stories"
|
7
|
+
task :stories => [:environment, "stories:purge", "stories:load"]
|
8
|
+
|
9
|
+
namespace :stories do
|
10
|
+
|
11
|
+
desc "Load the stories"
|
12
|
+
task :load => [:environment, "seed:load", "data:load"]
|
13
|
+
|
14
|
+
desc "Purge the stories"
|
15
|
+
task :purge => [:environment, "data:purge", "seed:purge"]
|
16
|
+
|
17
|
+
desc "Refresh to seed data"
|
18
|
+
task :seed => [:environment, "data:purge", "seed:purge", "seed:load"]
|
19
|
+
|
20
|
+
desc "Refresh to test data"
|
21
|
+
task :data => [:environment, "data:purge", "data:load"]
|
22
|
+
|
23
|
+
namespace :seed do
|
24
|
+
desc "Load Seed Data"
|
25
|
+
task :load => [:environment] do
|
26
|
+
StoryHelper.load_seed
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Purge Seed Data"
|
30
|
+
task :purge => [:environment] do
|
31
|
+
StoryHelper.purge_seed
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
namespace :data do
|
36
|
+
desc "Load test data"
|
37
|
+
task :load => [:environment] do
|
38
|
+
StoryHelper.load_data
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Purge test data"
|
42
|
+
task :purge => [:environment] do
|
43
|
+
StoryHelper.purge_data
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
11
47
|
end
|
12
48
|
|
13
49
|
# First, delete the Tasks we wish to override
|
@@ -3,15 +3,53 @@
|
|
3
3
|
class StoryHelper
|
4
4
|
self.extend StoryAccessors::Methods
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# load up the seed data for your application. This is data that should be loaded when the
|
7
|
+
# application is deployed to a server for the first time. For example, an Admin account and
|
8
|
+
# models like FileType that are database-level constants.
|
9
|
+
#
|
10
|
+
# This is best run as a series of calls to private methods:
|
11
|
+
# self.load_people
|
12
|
+
# self.load_posts
|
13
|
+
# etc...
|
14
|
+
def self.load_seed
|
8
15
|
|
9
16
|
end
|
10
17
|
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
# Purge the seed data that you loaded
|
19
|
+
#
|
20
|
+
# The best way to do this is as follows:
|
21
|
+
# [People, Posts, ... etc ].reverse.each do |model|
|
22
|
+
# model.destroy_all
|
23
|
+
# end
|
24
|
+
# You should have an array of the models *in the same order* as in your load method. You should
|
25
|
+
# have ALL of the models in the database in this table to be safe.
|
26
|
+
def self.purge_seed
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# Load up testing data for your test suite. Follows same pattern as load_seed
|
31
|
+
def self.load_data
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
# Purge the data that you loaded. Follows same pattern at purge_seed
|
36
|
+
def self.purge_data
|
37
|
+
self.purge_assets
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# Here you can run file system calls to clean out any content directories you use.
|
43
|
+
# For example:
|
44
|
+
# FileUtils.rm_rf(File.join(RAILS_ROOT, 'content', RAILS_ENV))
|
45
|
+
def self.purge_assets
|
46
|
+
|
15
47
|
end
|
16
48
|
|
17
|
-
|
49
|
+
### Put your Seed loading methods here:
|
50
|
+
|
51
|
+
|
52
|
+
### Put your data loading methods here:
|
53
|
+
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class ActionController::TestCase
|
2
|
+
extend StoryAccessors::Methods # this probably isn't the right thing to do....
|
3
|
+
|
4
|
+
# allows us to use the self.log_in function to log in a certain user
|
5
|
+
@@scoped_session = {}
|
6
|
+
|
7
|
+
# Used as a directive at the top of a functional test (to blanket log in this user)
|
8
|
+
# def self.log_in(user)
|
9
|
+
# #puts "logging in #{user.email}"
|
10
|
+
# @@scoped_session.merge!({:user_id => user.id})
|
11
|
+
# end
|
12
|
+
|
13
|
+
# invoke in setup (or within a specific test to override the setup method)
|
14
|
+
def log_in(user)
|
15
|
+
@@scoped_session[:user_id] = user.id
|
16
|
+
end
|
17
|
+
|
18
|
+
def log_out
|
19
|
+
@@scoped_session.delete(:user_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Used within a test to log in a specific user for a single test
|
23
|
+
# def log_in(user)
|
24
|
+
# old_user_id = @@scoped_session[:user_id]
|
25
|
+
# @@scoped_session[:user_id] = user.id
|
26
|
+
# yield
|
27
|
+
# ensure
|
28
|
+
# @@scoped_session[:user_id] = old_user_id
|
29
|
+
# end
|
30
|
+
|
31
|
+
[:get, :post, :put, :delete].each do |meth|
|
32
|
+
src = <<-END_OF_SRC
|
33
|
+
def #{meth.to_s}(action, parameters = nil, session = {}, flash = nil)
|
34
|
+
super(action, parameters, session.merge(@@scoped_session || {}), flash)
|
35
|
+
end
|
36
|
+
END_OF_SRC
|
37
|
+
class_eval src, __FILE__, __LINE__
|
38
|
+
end
|
39
|
+
|
40
|
+
def xhr(request_method, action, parameters = nil, session = {}, flash = nil)
|
41
|
+
super(request_method, action, parameters, session.merge(@@scoped_session || {}), flash)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/story-helper/version.rb
CHANGED
data/story-helper.gemspec
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.name = %q{story-helper}
|
3
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
4
6
|
|
5
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
8
|
s.authors = ["John Trupiano"]
|
7
|
-
s.date = %q{
|
9
|
+
s.date = %q{2009-01-30}
|
8
10
|
s.default_executable = %q{storify}
|
9
11
|
s.description = %q{A set of helpers/features to aid in implementing the StoryHelper concept in rails apps}
|
10
12
|
s.email = ["jtrupiano@gmail.com"]
|
11
13
|
s.executables = ["storify"]
|
12
|
-
s.extra_rdoc_files = ["History.txt", "Manifest.txt"
|
13
|
-
s.files = ["History.txt", "Manifest.txt", "README.
|
14
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
|
15
|
+
s.files = ["History.txt", "Manifest.txt", "README.textile", "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/conf/test_helper_extensions.rb", "lib/story-helper/version.rb", "story-helper.gemspec", "test/rails_version_test.rb", "test/test_story_helper.rb"]
|
14
16
|
s.has_rdoc = true
|
15
|
-
s.homepage = %q{http://github.com/jtrupiano/story-helper}
|
16
17
|
s.rdoc_options = ["--main", "README.txt"]
|
17
18
|
s.require_paths = ["lib"]
|
18
19
|
s.rubyforge_project = %q{johntrupiano}
|
19
|
-
s.rubygems_version = %q{1.
|
20
|
+
s.rubygems_version = %q{1.3.1}
|
20
21
|
s.summary = %q{A set of helpers/features to aid in implementing the StoryHelper concept in rails apps}
|
21
22
|
s.test_files = ["test/test_story_helper.rb"]
|
22
23
|
|
@@ -24,12 +25,12 @@ Gem::Specification.new do |s|
|
|
24
25
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
26
|
s.specification_version = 2
|
26
27
|
|
27
|
-
if
|
28
|
-
s.add_development_dependency(%q<hoe>, [">= 1.
|
28
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
29
|
+
s.add_development_dependency(%q<hoe>, [">= 1.8.2"])
|
29
30
|
else
|
30
|
-
s.add_dependency(%q<hoe>, [">= 1.
|
31
|
+
s.add_dependency(%q<hoe>, [">= 1.8.2"])
|
31
32
|
end
|
32
33
|
else
|
33
|
-
s.add_dependency(%q<hoe>, [">= 1.
|
34
|
+
s.add_dependency(%q<hoe>, [">= 1.8.2"])
|
34
35
|
end
|
35
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jtrupiano-story-helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Trupiano
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-30 00:00:00 -08:00
|
13
13
|
default_executable: storify
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
22
|
+
version: 1.8.2
|
23
23
|
version:
|
24
24
|
description: A set of helpers/features to aid in implementing the StoryHelper concept in rails apps
|
25
25
|
email:
|
@@ -31,23 +31,23 @@ extensions: []
|
|
31
31
|
extra_rdoc_files:
|
32
32
|
- History.txt
|
33
33
|
- Manifest.txt
|
34
|
-
- README.txt
|
35
34
|
files:
|
36
35
|
- History.txt
|
37
36
|
- Manifest.txt
|
38
|
-
- README.
|
37
|
+
- README.textile
|
39
38
|
- Rakefile
|
40
39
|
- bin/storify
|
41
40
|
- lib/story-helper.rb
|
42
41
|
- lib/story-helper/conf/story_accessors.rb
|
43
42
|
- lib/story-helper/conf/story_helper.rake
|
44
43
|
- lib/story-helper/conf/story_helper.rb
|
44
|
+
- lib/story-helper/conf/test_helper_extensions.rb
|
45
45
|
- lib/story-helper/version.rb
|
46
46
|
- story-helper.gemspec
|
47
47
|
- test/rails_version_test.rb
|
48
48
|
- test/test_story_helper.rb
|
49
49
|
has_rdoc: true
|
50
|
-
homepage:
|
50
|
+
homepage:
|
51
51
|
post_install_message:
|
52
52
|
rdoc_options:
|
53
53
|
- --main
|