behavior 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +97 -0
- data/Rakefile +43 -0
- data/app/controllers/admin/configs_controller.rb +20 -0
- data/app/helpers/behavior_helper.rb +8 -0
- data/app/models/behavior_config.rb +3 -0
- data/app/views/admin/configs/show.html.erb +20 -0
- data/app/views/layouts/admin.html.erb +11 -0
- data/behavior.gemspec +73 -0
- data/config/behavior.yml +18 -0
- data/config/routes.rb +5 -0
- data/features/admin_configs.feature +15 -0
- data/features/step_definitions/web_steps.rb +248 -0
- data/features/support/behavior_env.rb +3 -0
- data/features/support/env.rb +53 -0
- data/features/support/paths.rb +27 -0
- data/generators/behavior/USAGE +7 -0
- data/generators/behavior/behavior_generator.rb +9 -0
- data/generators/behavior/templates/20091210164854_create_behavior_configs.rb +16 -0
- data/generators/behavior/templates/behavior.yml +33 -0
- data/generators/definition.txt +0 -0
- data/lib/behavior.rb +73 -0
- data/rails/init.rb +1 -0
- data/spec/behavior_generator_spec.rb +43 -0
- data/spec/behavior_spec.rb +41 -0
- data/spec/blueprints.rb +8 -0
- data/spec/database.yml +21 -0
- data/spec/debug.log +1731 -0
- data/spec/helpers/behavior_helper_spec.rb +18 -0
- data/spec/schema.rb +6 -0
- data/spec/spec_helper.rb +42 -0
- metadata +89 -0
data/README.textile
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
h1. Behavior
|
2
|
+
|
3
|
+
Behavior is a Ruby on Rails plugin for storing application configuration variables in the database. You can use it to store things like a Site's Title, description and keywords, or for user definable things like a currency exchange rate, or minimum and maximum values.
|
4
|
+
|
5
|
+
The benefits of storing configuration in the database are:
|
6
|
+
|
7
|
+
- End users can easily edit the values
|
8
|
+
- Configuration is decoupled from the codebase
|
9
|
+
|
10
|
+
This is particularly useful for open source projects, where application settings shouldn't be stored in source code.
|
11
|
+
|
12
|
+
It's designed to be as simple to use and get up and running, and to be flexible in that it's both end user and developer friendly.
|
13
|
+
|
14
|
+
Although all config variables are ultimately stored in the database, you can set sensible defaults in a configuration file in the source code.
|
15
|
+
|
16
|
+
h2. Installation
|
17
|
+
|
18
|
+
Behavior is easy to install.
|
19
|
+
|
20
|
+
As a plugin:
|
21
|
+
|
22
|
+
<pre><code>./script/plugin install git://github.com/paulca/behavior.git</code></pre>
|
23
|
+
|
24
|
+
Or as a gem. Add this to your environment.rb:
|
25
|
+
|
26
|
+
<pre><code>config.gem 'behavior'</code></pre>
|
27
|
+
|
28
|
+
Generate the migration and sample behavior.yml:
|
29
|
+
|
30
|
+
<pre><code>./script/generate behavior</code></pre>
|
31
|
+
|
32
|
+
And run the migration:
|
33
|
+
|
34
|
+
<pre><code>rake db:migrate</code></pre>
|
35
|
+
|
36
|
+
h2. Basic Usage
|
37
|
+
|
38
|
+
There are two parts to how behavior works. First of all there is a config file, config/behavior.yml. This file controls the variables that are allowed to be set in the app.
|
39
|
+
|
40
|
+
For example, if you wanted to have access to a config variable "site_title", put this in behavior.yml:
|
41
|
+
|
42
|
+
<pre><code>site_title:
|
43
|
+
default: My Site</code></pre>
|
44
|
+
|
45
|
+
Now, within your app, you can access <pre><code>config[:site_title]</code></pre>.
|
46
|
+
|
47
|
+
If you want to update the config, call <pre><code>config.update(:site_title => "My New Title")</code></pre>
|
48
|
+
|
49
|
+
h2. Web Interface
|
50
|
+
|
51
|
+
behavior comes with a web interface that is available to your app straight away at <pre><code>http://localhost:3000/admin/config</code></pre>.
|
52
|
+
|
53
|
+
By default, this comes with no styling, but you can create a layout in <pre><code>app/layouts/admin.html.erb</code></pre>, or set a layout by setting <pre><code>Behavior::Setting.layout</code></pre>
|
54
|
+
|
55
|
+
For example, to use your standard application layout, create a <pre><code>config/initializers/behavior.rb</code></pre> like this:
|
56
|
+
|
57
|
+
<pre><code>Behavior::Settings.layout = 'application'</code></pre>
|
58
|
+
|
59
|
+
You can also add before_filters to protect the controller from outsiders:
|
60
|
+
|
61
|
+
<pre><code>Behavior::Settings.before_filters << 'require_admin_user'</code></pre>
|
62
|
+
|
63
|
+
If you want to control how the fields in the admin interface appear, you can add additional params in your behavior.yml file:
|
64
|
+
|
65
|
+
<pre><code>site_title:
|
66
|
+
name: Name of Your Site # sets the edit label
|
67
|
+
default: My Site # sets the default value
|
68
|
+
type: string # uses input type="text"
|
69
|
+
|
70
|
+
site_description:
|
71
|
+
name: Describe Your Site # sets the edit label
|
72
|
+
default: My Site # sets the default value
|
73
|
+
type: text # uses textarea
|
74
|
+
|
75
|
+
secret:
|
76
|
+
name: A Secret Passphrase # sets the edit label
|
77
|
+
default: passpass # sets the default value
|
78
|
+
type: password # uses input type="password"
|
79
|
+
</code></pre>
|
80
|
+
|
81
|
+
h2. Running the tests
|
82
|
+
|
83
|
+
You can run the tests by checking out the code into vendor/plugins of a Rails app and running:
|
84
|
+
|
85
|
+
<pre><code>rake</code></pre>
|
86
|
+
|
87
|
+
It also comes with a set of cucumber features:
|
88
|
+
|
89
|
+
<pre><code>cucumber</code></pre>
|
90
|
+
|
91
|
+
h2. About me
|
92
|
+
|
93
|
+
I'm Paul Campbell. I'm an avid Ruby on Rails web developer. Follow my ramblings at "http://www.pabcas.com":http://www.pabcas.com
|
94
|
+
|
95
|
+
Follow me on Twitter "http://twitter.com/paulca":http://twitter.com/paulca
|
96
|
+
|
97
|
+
Copyright (c) 2009 Paul Campbell, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc 'Default: run specs.'
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc 'Run the specs'
|
8
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
9
|
+
t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
|
10
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
11
|
+
end
|
12
|
+
|
13
|
+
PKG_FILES = FileList[
|
14
|
+
'[a-zA-Z]*',
|
15
|
+
'app/**/*',
|
16
|
+
'generators/**/*',
|
17
|
+
'config/*',
|
18
|
+
'lib/**/*',
|
19
|
+
'rails/**/*',
|
20
|
+
'spec/**/*',
|
21
|
+
'features/**/*'
|
22
|
+
]
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'jeweler'
|
26
|
+
Jeweler::Tasks.new do |s|
|
27
|
+
s.name = "behavior"
|
28
|
+
s.version = "0.1.0"
|
29
|
+
s.author = "Paul Campbell"
|
30
|
+
s.email = "paul@rslw.com"
|
31
|
+
s.homepage = "http://www.github.com/paulca/behavior"
|
32
|
+
s.platform = Gem::Platform::RUBY
|
33
|
+
s.summary = "A Rails plugin for storing application configuration in the database."
|
34
|
+
s.files = PKG_FILES.to_a
|
35
|
+
s.require_path = "lib"
|
36
|
+
s.has_rdoc = false
|
37
|
+
s.extra_rdoc_files = ["README.textile"]
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
41
|
+
end
|
42
|
+
|
43
|
+
Jeweler::GemcutterTasks.new
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Admin::ConfigsController < ApplicationController
|
2
|
+
|
3
|
+
layout Behavior::Settings.layout
|
4
|
+
Behavior::Settings.before_filters.each do |filter|
|
5
|
+
before_filter filter
|
6
|
+
end
|
7
|
+
|
8
|
+
helper :behavior
|
9
|
+
|
10
|
+
def show
|
11
|
+
@configs = config.all
|
12
|
+
end
|
13
|
+
|
14
|
+
def update
|
15
|
+
config.update(params[:conf])
|
16
|
+
flash[:notice] = "Config Changes Saved"
|
17
|
+
redirect_to admin_config_path
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module BehaviorHelper
|
2
|
+
|
3
|
+
def behavior_tag(conf)
|
4
|
+
return text_area_tag("conf[#{conf}]", config[conf], :id => conf) if config.meta[conf][:type] == 'text'
|
5
|
+
return password_field_tag("conf[#{conf}]", config[conf], :id => conf) if config.meta[conf][:type] == 'password'
|
6
|
+
text_field_tag("conf[#{conf}]", config[conf], :id => conf)
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<h2>Edit Configuration</h2>
|
2
|
+
|
3
|
+
<%- if !flash[:notice].blank? -%>
|
4
|
+
<div class="notice">
|
5
|
+
<%= flash[:notice] %>
|
6
|
+
</div>
|
7
|
+
<%- end -%>
|
8
|
+
|
9
|
+
<%- form_tag admin_config_path, :method => :put do -%>
|
10
|
+
|
11
|
+
<fieldset>
|
12
|
+
<%- @configs.each do |conf| -%>
|
13
|
+
<%= label_tag(conf, (config.meta[conf][:name])) %>
|
14
|
+
<%= behavior_tag(conf) %> <br />
|
15
|
+
<%- end -%>
|
16
|
+
</fieldset>
|
17
|
+
|
18
|
+
<%= submit_tag "Save" %>
|
19
|
+
|
20
|
+
<%- end -%>
|
data/behavior.gemspec
ADDED
@@ -0,0 +1,73 @@
|
|
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{behavior}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Paul Campbell"]
|
12
|
+
s.date = %q{2009-12-11}
|
13
|
+
s.email = %q{paul@rslw.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README.textile"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
"README.textile",
|
19
|
+
"Rakefile",
|
20
|
+
"app/controllers/admin/configs_controller.rb",
|
21
|
+
"app/helpers/behavior_helper.rb",
|
22
|
+
"app/models/behavior_config.rb",
|
23
|
+
"app/views/admin/configs/show.html.erb",
|
24
|
+
"app/views/layouts/admin.html.erb",
|
25
|
+
"behavior.gemspec",
|
26
|
+
"config/behavior.yml",
|
27
|
+
"config/routes.rb",
|
28
|
+
"features/admin_configs.feature",
|
29
|
+
"features/step_definitions/web_steps.rb",
|
30
|
+
"features/support/behavior_env.rb",
|
31
|
+
"features/support/env.rb",
|
32
|
+
"features/support/paths.rb",
|
33
|
+
"generators/behavior/USAGE",
|
34
|
+
"generators/behavior/behavior_generator.rb",
|
35
|
+
"generators/behavior/templates/20091210164854_create_behavior_configs.rb",
|
36
|
+
"generators/behavior/templates/behavior.yml",
|
37
|
+
"generators/definition.txt",
|
38
|
+
"lib/behavior.rb",
|
39
|
+
"rails/init.rb",
|
40
|
+
"spec/behavior_generator_spec.rb",
|
41
|
+
"spec/behavior_spec.rb",
|
42
|
+
"spec/blueprints.rb",
|
43
|
+
"spec/database.yml",
|
44
|
+
"spec/debug.log",
|
45
|
+
"spec/helpers/behavior_helper_spec.rb",
|
46
|
+
"spec/schema.rb",
|
47
|
+
"spec/spec_helper.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://www.github.com/paulca/behavior}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.3.5}
|
53
|
+
s.summary = %q{A Rails plugin for storing application configuration in the database.}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/behavior_generator_spec.rb",
|
56
|
+
"spec/behavior_spec.rb",
|
57
|
+
"spec/blueprints.rb",
|
58
|
+
"spec/helpers/behavior_helper_spec.rb",
|
59
|
+
"spec/schema.rb",
|
60
|
+
"spec/spec_helper.rb"
|
61
|
+
]
|
62
|
+
|
63
|
+
if s.respond_to? :specification_version then
|
64
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
65
|
+
s.specification_version = 3
|
66
|
+
|
67
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
68
|
+
else
|
69
|
+
end
|
70
|
+
else
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
data/config/behavior.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
email_address:
|
2
|
+
name: Email Address
|
3
|
+
type: string
|
4
|
+
default: example@example.com
|
5
|
+
|
6
|
+
email_name:
|
7
|
+
default: Site Administrator
|
8
|
+
type: string
|
9
|
+
|
10
|
+
password:
|
11
|
+
default: password
|
12
|
+
type: password
|
13
|
+
name: Password
|
14
|
+
|
15
|
+
description:
|
16
|
+
default: My Awesome Site
|
17
|
+
type: text
|
18
|
+
name: Description
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Feature: Editing Configuration
|
2
|
+
In order to set configuration variables in my app
|
3
|
+
As a user
|
4
|
+
I want to be able to see what configuration is available, and edit it
|
5
|
+
|
6
|
+
Scenario: Editing configuration
|
7
|
+
Given I am on the configuration page
|
8
|
+
Then I should see "Site Admin"
|
9
|
+
And I should see "Email Address"
|
10
|
+
And I should see "Email name"
|
11
|
+
|
12
|
+
When I fill in "Email Address" with "paul@rslw.com"
|
13
|
+
And I press "Save"
|
14
|
+
Then the "Email Address" field should contain "paul@rslw.com"
|
15
|
+
Then I should see "Config Changes Saved"
|
@@ -0,0 +1,248 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one.
|
5
|
+
|
6
|
+
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
8
|
+
|
9
|
+
module WithinHelpers
|
10
|
+
def with_scope(locator)
|
11
|
+
within(locator || 'html') { yield }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
World(WithinHelpers)
|
15
|
+
|
16
|
+
Given /^(?:|I )am on (.+)$/ do |page_name|
|
17
|
+
visit path_to(page_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
When /^(?:|I )go to (.+)$/ do |page_name|
|
21
|
+
visit path_to(page_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
When /^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/ do |button, selector|
|
25
|
+
with_scope(selector) do
|
26
|
+
click_button(button)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
When /^(?:|I )follow "([^\"]*)"(?: within "([^\"]*)")?$/ do |link, selector|
|
31
|
+
with_scope(selector) do
|
32
|
+
click_link(link)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, value, selector|
|
37
|
+
with_scope(selector) do
|
38
|
+
fill_in(field, :with => value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
|
43
|
+
with_scope(selector) do
|
44
|
+
fill_in(field, :with => value)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Use this to fill in an entire form with data from a table. Example:
|
49
|
+
#
|
50
|
+
# When I fill in the following:
|
51
|
+
# | Account Number | 5002 |
|
52
|
+
# | Expiry date | 2009-11-01 |
|
53
|
+
# | Note | Nice guy |
|
54
|
+
# | Wants Email? | |
|
55
|
+
#
|
56
|
+
# TODO: Add support for checkbox, select og option
|
57
|
+
# based on naming conventions.
|
58
|
+
#
|
59
|
+
When /^(?:|I )fill in the following(?: within "([^\"]*)"|)?:$/ do |fields, selector|
|
60
|
+
with_scope(selector) do
|
61
|
+
fields.rows_hash.each do |name, value|
|
62
|
+
When %{I fill in "#{name}" with "#{value}"}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
When /^(?:|I )select "([^\"]*)" from "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
|
68
|
+
with_scope(selector) do
|
69
|
+
select(value, :from => field)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Use this step in conjunction with Rail's datetime_select helper. For example:
|
74
|
+
# When I select "December 25, 2008 10:00" as the date and time
|
75
|
+
When /^(?:|I )select "([^\"]*)" as the date and time(?: within "([^\"]*)")?$/ do |time, selector|
|
76
|
+
with_scope(selector) do
|
77
|
+
select_datetime(time)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Use this step when using multiple datetime_select helpers on a page or
|
82
|
+
# you want to specify which datetime to select. Given the following view:
|
83
|
+
# <%= f.label :preferred %><br />
|
84
|
+
# <%= f.datetime_select :preferred %>
|
85
|
+
# <%= f.label :alternative %><br />
|
86
|
+
# <%= f.datetime_select :alternative %>
|
87
|
+
# The following steps would fill out the form:
|
88
|
+
# When I select "November 23, 2004 11:20" as the "Preferred" date and time
|
89
|
+
# And I select "November 25, 2004 10:30" as the "Alternative" date and time
|
90
|
+
When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time(?: within "([^\"]*)")?$/ do |datetime, datetime_label, selector|
|
91
|
+
with_scope(selector) do
|
92
|
+
select_datetime(datetime, :from => datetime_label)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Use this step in conjunction with Rail's time_select helper. For example:
|
97
|
+
# When I select "2:20PM" as the time
|
98
|
+
# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
|
99
|
+
# will convert the 2:20PM to 14:20 and then select it.
|
100
|
+
When /^(?:|I )select "([^\"]*)" as the time(?: within "([^\"]*)")?$/ do |time, selector|
|
101
|
+
with_scope(selector) do
|
102
|
+
select_time(time)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Use this step when using multiple time_select helpers on a page or you want to
|
107
|
+
# specify the name of the time on the form. For example:
|
108
|
+
# When I select "7:30AM" as the "Gym" time
|
109
|
+
When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time(?: within "([^\"]*)")?$/ do |time, time_label, selector|
|
110
|
+
with_scope(selector) do
|
111
|
+
select_time(time, :from => time_label)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Use this step in conjunction with Rail's date_select helper. For example:
|
116
|
+
# When I select "February 20, 1981" as the date
|
117
|
+
When /^(?:|I )select "([^\"]*)" as the date(?: within "([^\"]*)")?$/ do |date, selector|
|
118
|
+
with_scope(selector) do
|
119
|
+
select_date(date)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Use this step when using multiple date_select helpers on one page or
|
124
|
+
# you want to specify the name of the date on the form. For example:
|
125
|
+
# When I select "April 26, 1982" as the "Date of Birth" date
|
126
|
+
When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date(?: within "([^\"]*)")?$/ do |date, date_label, selector|
|
127
|
+
with_scope(selector) do
|
128
|
+
select_date(date, :from => date_label)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
When /^(?:|I )check "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
133
|
+
with_scope(selector) do
|
134
|
+
check(field)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
When /^(?:|I )uncheck "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
139
|
+
with_scope(selector) do
|
140
|
+
uncheck(field)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
When /^(?:|I )choose "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
145
|
+
with_scope(selector) do
|
146
|
+
choose(field)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
When /^(?:|I )attach the file at "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
|
151
|
+
with_scope(selector) do
|
152
|
+
attach_file(field, path)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
|
157
|
+
with_scope(selector) do
|
158
|
+
if defined?(Spec::Rails::Matchers)
|
159
|
+
has_content?(text).should be_true
|
160
|
+
else
|
161
|
+
assert has_content?(text)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
|
167
|
+
regexp = Regexp.new(regexp)
|
168
|
+
with_scope(selector) do
|
169
|
+
if defined?(Spec::Rails::Matchers)
|
170
|
+
has_xpath?('//*', :text => regexp).should be_true
|
171
|
+
else
|
172
|
+
assert has_xpath('//*', :text => regexp)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
|
178
|
+
with_scope(selector) do
|
179
|
+
if defined?(Spec::Rails::Matchers)
|
180
|
+
has_content?(text).should be_false
|
181
|
+
else
|
182
|
+
assert_not has_content?(text)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
|
188
|
+
regexp = Regexp.new(regexp)
|
189
|
+
with_scope(selector) do
|
190
|
+
if defined?(Spec::Rails::Matchers)
|
191
|
+
has_xpath?('//*', :text => regexp).should be_false
|
192
|
+
else
|
193
|
+
assert_not has_xpath?('//*', :text => regexp)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/ do |field, selector, value|
|
199
|
+
with_scope(selector) do
|
200
|
+
if defined?(Spec::Rails::Matchers)
|
201
|
+
field_labeled(field).value.should =~ /#{value}/
|
202
|
+
else
|
203
|
+
assert_match(/#{value}/, field_labeled(field).value)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should not contain "([^\"]*)"$/ do |field, selector, value|
|
209
|
+
with_scope(selector) do
|
210
|
+
if defined?(Spec::Rails::Matchers)
|
211
|
+
find_field(field).value.should_not =~ /#{value}/
|
212
|
+
else
|
213
|
+
assert_no_match(/#{value}/, find_field(field).value)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should be checked$/ do |label, selector|
|
219
|
+
with_scope(selector) do
|
220
|
+
if defined?(Spec::Rails::Matchers)
|
221
|
+
field_labeled(label)['checked'].should == 'checked'
|
222
|
+
else
|
223
|
+
assert field_labeled(label)['checked'] == 'checked'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector|
|
229
|
+
with_scope(selector) do
|
230
|
+
if defined?(Spec::Rails::Matchers)
|
231
|
+
field_labeled(label)['checked'].should_not == 'checked'
|
232
|
+
else
|
233
|
+
assert field_labeled(label)['checked'] != 'checked'
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
239
|
+
if defined?(Spec::Rails::Matchers)
|
240
|
+
URI.parse(current_url).path.should == path_to(page_name)
|
241
|
+
else
|
242
|
+
assert_equal path_to(page_name), URI.parse(current_url).path
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
Then /^show me the page$/ do
|
247
|
+
save_and_open_page
|
248
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one.
|
5
|
+
|
6
|
+
ENV["RAILS_ENV"] ||= "cucumber"
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
|
8
|
+
|
9
|
+
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
|
10
|
+
require 'cucumber/rails/rspec'
|
11
|
+
require 'cucumber/rails/world'
|
12
|
+
require 'cucumber/rails/active_record'
|
13
|
+
require 'cucumber/web/tableish'
|
14
|
+
|
15
|
+
require 'capybara/rails'
|
16
|
+
require 'capybara/cucumber'
|
17
|
+
require 'capybara/session'
|
18
|
+
require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
|
19
|
+
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
|
20
|
+
# order to ease the transition to Capybara we set the default here. If you'd
|
21
|
+
# prefer to use XPath just remove this line and adjust any selectors in your
|
22
|
+
# steps to use the XPath syntax.
|
23
|
+
Capybara.default_selector = :css
|
24
|
+
|
25
|
+
# If you set this to false, any error raised from within your app will bubble
|
26
|
+
# up to your step definition and out to cucumber unless you catch it somewhere
|
27
|
+
# on the way. You can make Rails rescue errors and render error pages on a
|
28
|
+
# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
|
29
|
+
#
|
30
|
+
# If you set this to true, Rails will rescue all errors and render error
|
31
|
+
# pages, more or less in the same way your application would behave in the
|
32
|
+
# default production environment. It's not recommended to do this for all
|
33
|
+
# of your scenarios, as this makes it hard to discover errors in your application.
|
34
|
+
ActionController::Base.allow_rescue = false
|
35
|
+
|
36
|
+
# If you set this to true, each scenario will run in a database transaction.
|
37
|
+
# You can still turn off transactions on a per-scenario basis, simply tagging
|
38
|
+
# a feature or scenario with the @no-txn tag. If you are using Capybara,
|
39
|
+
# tagging with @culerity or @javascript will also turn transactions off.
|
40
|
+
#
|
41
|
+
# If you set this to false, transactions will be off for all scenarios,
|
42
|
+
# regardless of whether you use @no-txn or not.
|
43
|
+
#
|
44
|
+
# Beware that turning transactions off will leave data in your database
|
45
|
+
# after each scenario, which can lead to hard-to-debug failures in
|
46
|
+
# subsequent scenarios. If you do this, we recommend you create a Before
|
47
|
+
# block that will explicitly put your database in a known state.
|
48
|
+
Cucumber::Rails::World.use_transactional_fixtures = true
|
49
|
+
|
50
|
+
# How to clean your database when transactions are turned off. See
|
51
|
+
# http://github.com/bmabey/database_cleaner for more info.
|
52
|
+
require 'database_cleaner'
|
53
|
+
DatabaseCleaner.strategy = :truncation
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module NavigationHelpers
|
2
|
+
# Maps a name to a path. Used by the
|
3
|
+
#
|
4
|
+
# When /^I go to (.+)$/ do |page_name|
|
5
|
+
#
|
6
|
+
# step definition in webrat_steps.rb
|
7
|
+
#
|
8
|
+
def path_to(page_name)
|
9
|
+
case page_name
|
10
|
+
|
11
|
+
when /the configuration page/
|
12
|
+
admin_config_path
|
13
|
+
|
14
|
+
# Add more mappings here.
|
15
|
+
# Here is a more fancy example:
|
16
|
+
#
|
17
|
+
# when /^(.*)'s profile page$/i
|
18
|
+
# user_profile_path(User.find_by_login($1))
|
19
|
+
|
20
|
+
else
|
21
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
22
|
+
"Now, go and add a mapping in #{__FILE__}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
World(NavigationHelpers)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class BehaviorGenerator < Rails::Generator::Base
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
m.directory 'db/migrate'
|
5
|
+
m.file "20091210164854_create_behavior_configs.rb", "db/migrate/20091210164854_create_behavior_configs.rb"
|
6
|
+
m.file "behavior.yml", "config/behavior.yml"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|