factory_scenarios 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -12
- data/Gemfile.lock +5 -8
- data/Rakefile +1 -0
- data/Readme.mdown +14 -2
- data/VERSION +1 -1
- data/app/assets/javascripts/factory_scenarios.coffee +7 -5
- data/app/controllers/factory_scenarios/scenarios_controller.rb +1 -1
- data/app/views/factory_scenarios/scenarios/index.html.haml +2 -2
- data/factory_scenarios.gemspec +7 -8
- data/lib/factory_scenarios/engine.rb +2 -0
- data/test/functional/factory_scenarios_controller_test.rb +83 -0
- data/test/helper.rb +76 -1
- data/test/test_factory_scenarios.rb +2 -124
- data/test/unit/test_scenario.rb +104 -0
- metadata +25 -37
data/Gemfile
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
2
|
|
6
|
-
gem "rails", "
|
3
|
+
gem "rails", ">= 3.1"
|
7
4
|
gem "dkastner-moneta", "~> 0.7"
|
8
5
|
gem "factory_girl", "~> 2", :require => false
|
9
6
|
gem "warden", "~> 1.0"
|
@@ -16,12 +13,5 @@ group :development do
|
|
16
13
|
gem "shoulda", ">= 0"
|
17
14
|
gem "bundler", "~> 1.1.rc8"
|
18
15
|
gem "jeweler", "~> 1.8.3"
|
19
|
-
|
20
|
-
platform :ruby_18 do
|
21
|
-
gem "rcov", ">= 0"
|
22
|
-
end
|
23
|
-
|
24
|
-
platform :ruby_19 do
|
25
|
-
gem "simplecov", ">= 0"
|
26
|
-
end
|
16
|
+
gem "test_engine"
|
27
17
|
end
|
data/Gemfile.lock
CHANGED
@@ -76,7 +76,6 @@ GEM
|
|
76
76
|
rdoc (~> 3.4)
|
77
77
|
thor (~> 0.14.6)
|
78
78
|
rake (0.9.2.2)
|
79
|
-
rcov (1.0.0)
|
80
79
|
rdoc (3.12)
|
81
80
|
json (~> 1.4)
|
82
81
|
shoulda (3.0.1)
|
@@ -84,14 +83,13 @@ GEM
|
|
84
83
|
shoulda-matchers (~> 1.0.0)
|
85
84
|
shoulda-context (1.0.0)
|
86
85
|
shoulda-matchers (1.0.0)
|
87
|
-
simplecov (0.6.1)
|
88
|
-
multi_json (~> 1.0)
|
89
|
-
simplecov-html (~> 0.5.3)
|
90
|
-
simplecov-html (0.5.3)
|
91
86
|
sprockets (2.1.2)
|
92
87
|
hike (~> 1.2)
|
93
88
|
rack (~> 1.0)
|
94
89
|
tilt (~> 1.1, != 1.3.0)
|
90
|
+
test_engine (0.0.4)
|
91
|
+
bundler
|
92
|
+
rails (> 3)
|
95
93
|
thor (0.14.6)
|
96
94
|
tilt (1.3.3)
|
97
95
|
treetop (1.4.10)
|
@@ -111,8 +109,7 @@ DEPENDENCIES
|
|
111
109
|
haml (~> 3.0)
|
112
110
|
hashie (~> 1.1)
|
113
111
|
jeweler (~> 1.8.3)
|
114
|
-
rails (
|
115
|
-
rcov
|
112
|
+
rails (>= 3.1)
|
116
113
|
shoulda
|
117
|
-
|
114
|
+
test_engine
|
118
115
|
warden (~> 1.0)
|
data/Rakefile
CHANGED
data/Readme.mdown
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# factory_scenarios/mail_preview
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/collin/factory_scenarios.png)](http://travis-ci.org/collin/factory_scenarios)
|
4
|
+
|
3
5
|
Login as users defined in your FactoryGirl factories.
|
4
6
|
|
5
7
|
Preview email while logged in as users defined in your FactoryGirl factories.
|
@@ -12,6 +14,15 @@ Preview email while logged in as users defined in your FactoryGirl factories.
|
|
12
14
|
end
|
13
15
|
* Run bundle install
|
14
16
|
|
17
|
+
|
18
|
+
## Tests
|
19
|
+
|
20
|
+
To test with your desired version of rails, do this:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
RAILS_VERSION=3.1.4 bundel exec rake test
|
24
|
+
```
|
25
|
+
|
15
26
|
## Configuration
|
16
27
|
|
17
28
|
* FactoryScenarios is a mountable engine. Add a line like this to your routes.rb file:
|
@@ -22,9 +33,11 @@ Preview email while logged in as users defined in your FactoryGirl factories.
|
|
22
33
|
end
|
23
34
|
```
|
24
35
|
|
25
|
-
*
|
36
|
+
* The current configuration options are as follows
|
26
37
|
- iframe_width: sets the width of the iframe that your site will appear in, defaults to 1000px
|
27
38
|
- user_class: your users class, defaults to User
|
39
|
+
- open_in_iframe: by default factory_scenarios will open your site in an iframe leaving the scenarios on the left,
|
40
|
+
if you don't desire this functionality you can set this option to false.
|
28
41
|
* <b> Important Note </b>
|
29
42
|
- You need to have active_reload installed in your application to utilize this gem successfully. The consequences of not
|
30
43
|
having this gem install will be errors when trying to login using your factories.
|
@@ -104,7 +117,6 @@ Preview email while logged in as users defined in your FactoryGirl factories.
|
|
104
117
|
|
105
118
|
|
106
119
|
## Todo
|
107
|
-
* Remove hard coded reference to BaseHelper, add as configuration option.
|
108
120
|
|
109
121
|
## Contributing to factory_scenarios
|
110
122
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -1,7 +1,9 @@
|
|
1
1
|
jQuery ($) ->
|
2
2
|
$("li a").on "click", (event) ->
|
3
|
-
$(
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
if $(this).data('open_in_iframe') == 'true'
|
4
|
+
$(".current").removeClass("current")
|
5
|
+
$(this).closest("li").addClass("current")
|
6
|
+
$("iframe").attr "src", $(".current a:first-child").attr("href")
|
7
|
+
else
|
8
|
+
console.log(this)
|
9
|
+
window.location = this.href
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module FactoryScenarios
|
2
2
|
class ScenariosController < EngineController
|
3
|
+
include FactoryScenarios::ScenariosHelper
|
3
4
|
|
4
5
|
def index
|
5
6
|
set_iframe_params
|
@@ -9,7 +10,6 @@ module FactoryScenarios
|
|
9
10
|
|
10
11
|
def enact
|
11
12
|
user_for_scenario = Scenario.find(params[:id]).enact(!!params[:clear])
|
12
|
-
|
13
13
|
login_to_scenario user_for_scenario
|
14
14
|
|
15
15
|
if respond_to?(:handle_factory_scenario)
|
@@ -9,8 +9,8 @@
|
|
9
9
|
%li(class="#{"current" if scenario.find_user && scenario.find_user == current_user}")
|
10
10
|
"#{scenario.name.titlecase}"
|
11
11
|
.actions
|
12
|
-
=
|
13
|
-
=
|
12
|
+
= scenario_link scenario
|
13
|
+
= reload_scenario_link scenario
|
14
14
|
- else
|
15
15
|
%h2 There are no defined scenarios.
|
16
16
|
%p Make sure you are loading your scenarios.
|
data/factory_scenarios.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "factory_scenarios"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Collin Miller"]
|
@@ -38,8 +38,10 @@ Gem::Specification.new do |s|
|
|
38
38
|
"lib/factory_scenarios/engine.rb",
|
39
39
|
"lib/factory_scenarios/mail.rb",
|
40
40
|
"lib/factory_scenarios/mail/preview.rb",
|
41
|
+
"test/functional/factory_scenarios_controller_test.rb",
|
41
42
|
"test/helper.rb",
|
42
|
-
"test/test_factory_scenarios.rb"
|
43
|
+
"test/test_factory_scenarios.rb",
|
44
|
+
"test/unit/test_scenario.rb"
|
43
45
|
]
|
44
46
|
s.homepage = "http://github.com/collin/factory_scenarios"
|
45
47
|
s.licenses = ["MIT"]
|
@@ -60,8 +62,7 @@ Gem::Specification.new do |s|
|
|
60
62
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
61
63
|
s.add_development_dependency(%q<bundler>, ["~> 1.1.rc8"])
|
62
64
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
63
|
-
s.add_development_dependency(%q<
|
64
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<test_engine>, [">= 0"])
|
65
66
|
else
|
66
67
|
s.add_dependency(%q<rails>, ["~> 3.0"])
|
67
68
|
s.add_dependency(%q<dkastner-moneta>, ["~> 0.7"])
|
@@ -72,8 +73,7 @@ Gem::Specification.new do |s|
|
|
72
73
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
73
74
|
s.add_dependency(%q<bundler>, ["~> 1.1.rc8"])
|
74
75
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
75
|
-
s.add_dependency(%q<
|
76
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
76
|
+
s.add_dependency(%q<test_engine>, [">= 0"])
|
77
77
|
end
|
78
78
|
else
|
79
79
|
s.add_dependency(%q<rails>, ["~> 3.0"])
|
@@ -85,8 +85,7 @@ Gem::Specification.new do |s|
|
|
85
85
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
86
86
|
s.add_dependency(%q<bundler>, ["~> 1.1.rc8"])
|
87
87
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
88
|
-
s.add_dependency(%q<
|
89
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
88
|
+
s.add_dependency(%q<test_engine>, [">= 0"])
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
@@ -5,6 +5,7 @@ module FactoryScenarios
|
|
5
5
|
property :user_class
|
6
6
|
property :factory_scenarios_moneta_backend
|
7
7
|
property :factory_scenarios_moneta_config
|
8
|
+
property :open_in_iframe
|
8
9
|
end
|
9
10
|
|
10
11
|
module ::FactoryGirl
|
@@ -33,6 +34,7 @@ module FactoryScenarios
|
|
33
34
|
@config ||= AppConfiguration.new(
|
34
35
|
:user_class => 'User',
|
35
36
|
:iframe_width => '80%',
|
37
|
+
:open_in_iframe => true,
|
36
38
|
:factory_scenarios_moneta_backend => :YAML,
|
37
39
|
:factory_scenarios_moneta_config => {
|
38
40
|
:path => "#{Rails.root.to_s}/db/factory_scenarios.#{Rails.env}.yml"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class FactoryScenariosControllerTest < ActionController::TestCase
|
3
|
+
tests FactoryScenarios::ScenariosController
|
4
|
+
|
5
|
+
self.custom_routes = proc do
|
6
|
+
mount FactoryScenarios::Engine => "/factory_scenarios", as: :factory_scenarios
|
7
|
+
end
|
8
|
+
|
9
|
+
context "#index" do
|
10
|
+
should "set the iframe width" do
|
11
|
+
User.meta_mock :where, []
|
12
|
+
get(:index, :use_route => :factory_scenarios)
|
13
|
+
assert_equal "80%", assigns(:width)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "#enact" do
|
18
|
+
|
19
|
+
class FactoryScenarios::ScenariosController
|
20
|
+
def current_user
|
21
|
+
@current_user
|
22
|
+
end
|
23
|
+
|
24
|
+
def sign_in(scope, user)
|
25
|
+
@current_user = user
|
26
|
+
end
|
27
|
+
|
28
|
+
def sign_out(user)
|
29
|
+
@current_user = null
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
setup do
|
34
|
+
@path = FactoryScenarios.config.factory_scenarios_moneta_config[:path] = "./test/factory_scenarios.test.yml"
|
35
|
+
@scenario = FactoryScenarios::Scenario.new(FactoryGirl.factories.first)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "login as user for scenario" do
|
39
|
+
user = User.new
|
40
|
+
User.meta_mock :where, [user]
|
41
|
+
get(:enact, :id => "user", :use_route => :factory_scenarios)
|
42
|
+
assert_equal user, assigns(:current_user)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "not clear current scenario if clear parm isnt 1" do
|
46
|
+
@scenario.user_id = 30
|
47
|
+
user = User.new
|
48
|
+
User.meta_mock :where, [user]
|
49
|
+
get(:enact, :id => "user", :use_route => :factory_scenarios)
|
50
|
+
assert_equal 30, @scenario.user_id
|
51
|
+
end
|
52
|
+
|
53
|
+
should "clear current scenario if clear param is 1" do
|
54
|
+
@scenario.user_id = 30
|
55
|
+
user = User.new
|
56
|
+
User.meta_mock :where, [user]
|
57
|
+
get(:enact, :id => "user", :clear => "1", :use_route => :factory_scenarios)
|
58
|
+
assert_not_equal 30, @scenario.user_id
|
59
|
+
end
|
60
|
+
|
61
|
+
should "redirect to /" do
|
62
|
+
user = User.new
|
63
|
+
User.meta_mock :where, [user]
|
64
|
+
get(:enact, :id => "user", :use_route => :factory_scenarios)
|
65
|
+
assert_redirected_to "/"
|
66
|
+
end
|
67
|
+
|
68
|
+
should "call handle_factory_scenario instead of redirecting to / if it is defined" do
|
69
|
+
class FactoryScenarios::ScenariosController
|
70
|
+
def handle_factory_scenario
|
71
|
+
redirect_to "/other"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
user = User.new
|
76
|
+
User.meta_mock :where, [user]
|
77
|
+
get(:enact, :id => "user", :use_route => :factory_scenarios)
|
78
|
+
assert_redirected_to "/other"
|
79
|
+
|
80
|
+
FactoryScenarios::ScenariosController.send(:remove_method, :handle_factory_scenario)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/test/helper.rb
CHANGED
@@ -9,10 +9,85 @@ rescue Bundler::BundlerError => e
|
|
9
9
|
end
|
10
10
|
require 'test/unit'
|
11
11
|
require 'shoulda'
|
12
|
+
require 'rails'
|
13
|
+
require 'rails/test_help'
|
12
14
|
|
13
15
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
16
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
17
|
require 'factory_scenarios'
|
16
18
|
|
17
|
-
|
19
|
+
# Mocks
|
20
|
+
def Object.meta_mock(method, _return)
|
21
|
+
(class << self; self end).send(:define_method, method) {|*args| _return }
|
18
22
|
end
|
23
|
+
|
24
|
+
require "factory_girl"
|
25
|
+
require "active_record"
|
26
|
+
|
27
|
+
class ::User
|
28
|
+
def save!; true end
|
29
|
+
def id
|
30
|
+
@id ||= rand(10000).to_i
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ::NotUser; end
|
35
|
+
|
36
|
+
FactoryGirl.define do
|
37
|
+
factory :user do; end
|
38
|
+
factory :not_user do; end
|
39
|
+
factory :user_child, :parent => :user do; end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Like with_routing except:
|
44
|
+
#
|
45
|
+
# * Can be used across an entire TestCase
|
46
|
+
# * Can work with a real browser (i.e. Capybara) in integration tests.
|
47
|
+
# * Routes are appended to already defined routes
|
48
|
+
#
|
49
|
+
# Just assign a block to the class attribute "custom_routes". This block will
|
50
|
+
# execute as if it is being called from within the routes.rb draw block.
|
51
|
+
module TestRoutes
|
52
|
+
extend ActiveSupport::Concern
|
53
|
+
|
54
|
+
included do
|
55
|
+
class_attribute :custom_routes
|
56
|
+
setup :install_routes
|
57
|
+
teardown :restore_routes
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def install_routes
|
63
|
+
# Easier to refer to
|
64
|
+
routes = Rails.application.routes
|
65
|
+
|
66
|
+
# Clear out any already loaded routes
|
67
|
+
routes.disable_clear_and_finalize = true
|
68
|
+
routes.clear!
|
69
|
+
|
70
|
+
# Load routes from application and engines
|
71
|
+
Rails.application.routes_reloader.paths.each{ |path| load(path) }
|
72
|
+
|
73
|
+
# Bring custom route block into closure and eval in context of draw
|
74
|
+
if custom = self.class.custom_routes
|
75
|
+
routes.draw {instance_eval &custom}
|
76
|
+
end
|
77
|
+
|
78
|
+
ensure
|
79
|
+
# Wrap up route defination
|
80
|
+
routes.disable_clear_and_finalize = false
|
81
|
+
routes.finalize!
|
82
|
+
end
|
83
|
+
|
84
|
+
def restore_routes
|
85
|
+
# Go back to just whatever the app and engines say
|
86
|
+
Rails.application.reload_routes!
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
class ActionController::TestCase
|
92
|
+
include TestRoutes
|
93
|
+
end
|
@@ -3,27 +3,6 @@ require 'pathname'
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'moneta/adapters/yaml'
|
5
5
|
|
6
|
-
# Mocks
|
7
|
-
def Object.meta_mock(method, _return)
|
8
|
-
(class << self; self end).send(:define_method, method) {|*args| _return }
|
9
|
-
end
|
10
|
-
|
11
|
-
require "./../factory_scenarios/app/models/factory_scenarios/scenario"
|
12
|
-
require "factory_girl"
|
13
|
-
require "active_record"
|
14
|
-
class ::User
|
15
|
-
def save!; true end
|
16
|
-
def id
|
17
|
-
@id ||= rand(10000).to_i
|
18
|
-
end
|
19
|
-
end
|
20
|
-
class ::NotUser; end
|
21
|
-
FactoryGirl.define do
|
22
|
-
factory :user do; end
|
23
|
-
factory :not_user do; end
|
24
|
-
factory :user_child, :parent => :user do; end
|
25
|
-
end
|
26
|
-
|
27
6
|
class TestFactoryScenarios < Test::Unit::TestCase
|
28
7
|
DEFAULT_FILE_PATH = "/db/factory_scenarios.development.yml"
|
29
8
|
context "storage" do
|
@@ -34,6 +13,7 @@ class TestFactoryScenarios < Test::Unit::TestCase
|
|
34
13
|
should "has default configuration" do
|
35
14
|
assert_equal "User", FactoryScenarios.config.user_class
|
36
15
|
assert_equal "80%", FactoryScenarios.config.iframe_width
|
16
|
+
assert_equal true, FactoryScenarios.config.open_in_iframe
|
37
17
|
assert_equal :YAML, FactoryScenarios.config.factory_scenarios_moneta_backend
|
38
18
|
assert_equal DEFAULT_FILE_PATH, FactoryScenarios.config.factory_scenarios_moneta_config[:path]
|
39
19
|
end
|
@@ -45,106 +25,4 @@ class TestFactoryScenarios < Test::Unit::TestCase
|
|
45
25
|
end
|
46
26
|
|
47
27
|
end
|
48
|
-
|
49
|
-
context FactoryScenarios::Scenario do
|
50
|
-
setup do
|
51
|
-
@path = FactoryScenarios.config.factory_scenarios_moneta_config[:path] = "./test/factory_scenarios.test.yml"
|
52
|
-
@scenario = FactoryScenarios::Scenario.new(FactoryGirl.factories.first)
|
53
|
-
end
|
54
|
-
|
55
|
-
should "have a storage" do
|
56
|
-
assert_equal Moneta::Adapters::YAML, @scenario.storage.class
|
57
|
-
end
|
58
|
-
|
59
|
-
context "Scenario.all" do
|
60
|
-
should "return scenarios only for user factories" do
|
61
|
-
assert_equal ["user", "user_child"], FactoryScenarios::Scenario.all.map(&:name)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "Scenario.find" do
|
66
|
-
should "find a scenario by factory name" do
|
67
|
-
assert_equal nil, FactoryScenarios::Scenario.find("not_user")
|
68
|
-
assert_equal "user", FactoryScenarios::Scenario.find("user").name
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "#enact" do
|
73
|
-
context "when persisted? is true" do
|
74
|
-
setup do
|
75
|
-
@user = User.new
|
76
|
-
User.meta_mock(:where, [@user])
|
77
|
-
end
|
78
|
-
|
79
|
-
should "clear if do_clear is true" do
|
80
|
-
@scenario.user_id = 20
|
81
|
-
@scenario.enact(true)
|
82
|
-
assert_equal 0, @scenario.user_id
|
83
|
-
end
|
84
|
-
|
85
|
-
should "not clear if do_clear isnt true" do
|
86
|
-
@scenario.user_id = 20
|
87
|
-
@scenario.enact
|
88
|
-
assert_equal 20, @scenario.user_id
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
should "create a new user if scenario isn't persisted and do_clear is true" do
|
93
|
-
User.meta_mock(:where, [])
|
94
|
-
assert_not_equal nil, @scenario.enact(true)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context "#find_user" do
|
99
|
-
should "return first found user" do
|
100
|
-
found = User.new
|
101
|
-
User.meta_mock(:where, [found])
|
102
|
-
assert_equal found, @scenario.find_user
|
103
|
-
end
|
104
|
-
|
105
|
-
should "return nothing when no users found" do
|
106
|
-
User.meta_mock(:where, [])
|
107
|
-
assert_equal nil, @scenario.find_user
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
should "not be persisted if User.where returns empty array" do
|
112
|
-
User.meta_mock :where, []
|
113
|
-
assert !@scenario.persisted?
|
114
|
-
end
|
115
|
-
|
116
|
-
should "be persisted if User.where returns a user" do
|
117
|
-
User.meta_mock :where, [User.new]
|
118
|
-
assert @scenario.persisted?
|
119
|
-
end
|
120
|
-
|
121
|
-
should "constantize the configured user class" do
|
122
|
-
assert_equal User, @scenario.user_class
|
123
|
-
end
|
124
|
-
|
125
|
-
should "get its name from it's factory" do
|
126
|
-
assert_equal "user", @scenario.name
|
127
|
-
end
|
128
|
-
|
129
|
-
context "#user_id" do
|
130
|
-
should "get its user_id from storage" do
|
131
|
-
@scenario.storage["user"] = 50
|
132
|
-
assert_equal 50, @scenario.user_id
|
133
|
-
end
|
134
|
-
|
135
|
-
should "not have a user_id of 0 if storage doesn't have it" do
|
136
|
-
@scenario.storage["user"] = 50
|
137
|
-
@scenario.storage.delete "user"
|
138
|
-
assert_equal 0, @scenario.user_id
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context "#clear" do
|
143
|
-
should "clear the user_id for a the factory" do
|
144
|
-
@scenario.storage["name"] = 500
|
145
|
-
@scenario.clear
|
146
|
-
assert_equal 0, @scenario.user_id
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
28
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "helper"
|
2
|
+
class TestScenario < Test::Unit::TestCase
|
3
|
+
context FactoryScenarios::Scenario do
|
4
|
+
setup do
|
5
|
+
@path = FactoryScenarios.config.factory_scenarios_moneta_config[:path] = "./test/factory_scenarios.test.yml"
|
6
|
+
@scenario = FactoryScenarios::Scenario.new(FactoryGirl.factories.first)
|
7
|
+
end
|
8
|
+
|
9
|
+
should "have a storage" do
|
10
|
+
assert_equal Moneta::Adapters::YAML, @scenario.storage.class
|
11
|
+
end
|
12
|
+
|
13
|
+
context "Scenario.all" do
|
14
|
+
should "return scenarios only for user factories" do
|
15
|
+
assert_equal ["user", "user_child"], FactoryScenarios::Scenario.all.map(&:name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "Scenario.find" do
|
20
|
+
should "find a scenario by factory name" do
|
21
|
+
assert_equal nil, FactoryScenarios::Scenario.find("not_user")
|
22
|
+
assert_equal "user", FactoryScenarios::Scenario.find("user").name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "#enact" do
|
27
|
+
context "when persisted? is true" do
|
28
|
+
setup do
|
29
|
+
@user = User.new
|
30
|
+
User.meta_mock(:where, [@user])
|
31
|
+
end
|
32
|
+
|
33
|
+
should "clear if do_clear is true" do
|
34
|
+
@scenario.user_id = 20
|
35
|
+
@scenario.enact(true)
|
36
|
+
assert_equal 0, @scenario.user_id
|
37
|
+
end
|
38
|
+
|
39
|
+
should "not clear if do_clear isnt true" do
|
40
|
+
@scenario.user_id = 20
|
41
|
+
@scenario.enact
|
42
|
+
assert_equal 20, @scenario.user_id
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
should "create a new user if scenario isn't persisted and do_clear is true" do
|
47
|
+
User.meta_mock(:where, [])
|
48
|
+
assert_not_equal nil, @scenario.enact(true)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "#find_user" do
|
53
|
+
should "return first found user" do
|
54
|
+
found = User.new
|
55
|
+
User.meta_mock(:where, [found])
|
56
|
+
assert_equal found, @scenario.find_user
|
57
|
+
end
|
58
|
+
|
59
|
+
should "return nothing when no users found" do
|
60
|
+
User.meta_mock(:where, [])
|
61
|
+
assert_equal nil, @scenario.find_user
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
should "not be persisted if User.where returns empty array" do
|
66
|
+
User.meta_mock :where, []
|
67
|
+
assert !@scenario.persisted?
|
68
|
+
end
|
69
|
+
|
70
|
+
should "be persisted if User.where returns a user" do
|
71
|
+
User.meta_mock :where, [User.new]
|
72
|
+
assert @scenario.persisted?
|
73
|
+
end
|
74
|
+
|
75
|
+
should "constantize the configured user class" do
|
76
|
+
assert_equal User, @scenario.user_class
|
77
|
+
end
|
78
|
+
|
79
|
+
should "get its name from it's factory" do
|
80
|
+
assert_equal "user", @scenario.name
|
81
|
+
end
|
82
|
+
|
83
|
+
context "#user_id" do
|
84
|
+
should "get its user_id from storage" do
|
85
|
+
@scenario.storage["user"] = 50
|
86
|
+
assert_equal 50, @scenario.user_id
|
87
|
+
end
|
88
|
+
|
89
|
+
should "not have a user_id of 0 if storage doesn't have it" do
|
90
|
+
@scenario.storage["user"] = 50
|
91
|
+
@scenario.storage.delete "user"
|
92
|
+
assert_equal 0, @scenario.user_id
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "#clear" do
|
97
|
+
should "clear the user_id for a the factory" do
|
98
|
+
@scenario.storage["name"] = 500
|
99
|
+
@scenario.clear
|
100
|
+
assert_equal 0, @scenario.user_id
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_scenarios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-16 00:00:00.
|
12
|
+
date: 2012-03-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &2161300820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2161300820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: dkastner-moneta
|
27
|
-
requirement: &
|
27
|
+
requirement: &2161300340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0.7'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2161300340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: factory_girl
|
38
|
-
requirement: &
|
38
|
+
requirement: &2161299860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2161299860
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: warden
|
49
|
-
requirement: &
|
49
|
+
requirement: &2161299380 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '1.0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2161299380
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: haml
|
60
|
-
requirement: &
|
60
|
+
requirement: &2161298900 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '3.0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2161298900
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: hashie
|
71
|
-
requirement: &
|
71
|
+
requirement: &2161298420 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '1.1'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2161298420
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: shoulda
|
82
|
-
requirement: &
|
82
|
+
requirement: &2161297940 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2161297940
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: bundler
|
93
|
-
requirement: &
|
93
|
+
requirement: &2161297460 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 1.1.rc8
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2161297460
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: jeweler
|
104
|
-
requirement: &
|
104
|
+
requirement: &2161296980 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 1.8.3
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *2161296980
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
|
-
name:
|
115
|
-
requirement: &
|
114
|
+
name: test_engine
|
115
|
+
requirement: &2161296500 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,18 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
124
|
-
- !ruby/object:Gem::Dependency
|
125
|
-
name: simplecov
|
126
|
-
requirement: &70207505235000 !ruby/object:Gem::Requirement
|
127
|
-
none: false
|
128
|
-
requirements:
|
129
|
-
- - ! '>='
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: *70207505235000
|
123
|
+
version_requirements: *2161296500
|
135
124
|
description: Build your factory and log-in in a single click. Also see what your emails
|
136
125
|
look like and enter your workflows by clickig on the links in the email
|
137
126
|
email: collintmiller@gmail.com
|
@@ -162,8 +151,10 @@ files:
|
|
162
151
|
- lib/factory_scenarios/engine.rb
|
163
152
|
- lib/factory_scenarios/mail.rb
|
164
153
|
- lib/factory_scenarios/mail/preview.rb
|
154
|
+
- test/functional/factory_scenarios_controller_test.rb
|
165
155
|
- test/helper.rb
|
166
156
|
- test/test_factory_scenarios.rb
|
157
|
+
- test/unit/test_scenario.rb
|
167
158
|
homepage: http://github.com/collin/factory_scenarios
|
168
159
|
licenses:
|
169
160
|
- MIT
|
@@ -177,9 +168,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
168
|
- - ! '>='
|
178
169
|
- !ruby/object:Gem::Version
|
179
170
|
version: '0'
|
180
|
-
segments:
|
181
|
-
- 0
|
182
|
-
hash: -2178813061097835124
|
183
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
172
|
none: false
|
185
173
|
requirements:
|