hermes 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/lib/hermes.rb +7 -1
- data/lib/hermes/actions.rb +81 -0
- data/lib/hermes/assertions.rb +34 -29
- data/lib/hermes/builders.rb +46 -21
- data/lib/hermes/context.rb +0 -2
- data/lib/hermes/integration_case.rb +7 -3
- data/lib/hermes/rails.rb +4 -0
- data/lib/hermes/scopes.rb +32 -0
- data/lib/hermes/version.rb +1 -1
- data/test/builders.rb +13 -0
- data/test/fixtures/users.yml +4 -0
- data/test/hermes/actions_test.rb +118 -0
- data/test/hermes/assertions_test.rb +493 -0
- data/test/hermes/builders_test.rb +109 -0
- data/test/hermes/context_test.rb +5 -0
- data/test/hermes/scopes_test.rb +47 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/controllers/application_controller.rb +3 -0
- data/test/rails_app/app/controllers/users_controller.rb +23 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/models/user.rb +11 -0
- data/test/rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/rails_app/app/views/users/index.html.erb +10 -0
- data/test/rails_app/app/views/users/new.html.erb +62 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +42 -0
- data/test/rails_app/config/boot.rb +10 -0
- data/test/rails_app/config/database.yml +20 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +26 -0
- data/test/rails_app/config/environments/production.rb +49 -0
- data/test/rails_app/config/environments/test.rb +35 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/inflections.rb +10 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/locales/en.yml +5 -0
- data/test/rails_app/config/routes.rb +7 -0
- data/test/rails_app/db/migrate/20110228170406_create_users.rb +15 -0
- data/test/rails_app/db/schema.rb +21 -0
- data/test/rails_app/log/development.log +29 -0
- data/test/rails_app/log/production.log +0 -0
- data/test/rails_app/log/server.log +0 -0
- data/test/rails_app/log/test.log +1519 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/public/javascripts/application.js +2 -0
- data/test/rails_app/public/javascripts/controls.js +965 -0
- data/test/rails_app/public/javascripts/dragdrop.js +974 -0
- data/test/rails_app/public/javascripts/effects.js +1123 -0
- data/test/rails_app/public/javascripts/prototype.js +6001 -0
- data/test/rails_app/public/javascripts/rails.js +191 -0
- data/test/rails_app/script/rails +6 -0
- data/test/support/assertions.rb +23 -0
- data/test/support/models.rb +11 -0
- data/test/test_helper.rb +29 -3
- metadata +108 -7
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BuildersTest < Hermes::IntegrationCase
|
4
|
+
FIXTURE_DATE = Time.parse("Thu, 03 Mar 2011 18:11:26 UTC +00:00").utc
|
5
|
+
fixtures :users
|
6
|
+
|
7
|
+
context "building models based on fixtures" do
|
8
|
+
test 'creating a model' do
|
9
|
+
user = create_user
|
10
|
+
|
11
|
+
assert_equal "The Super User", user.name
|
12
|
+
assert_equal FIXTURE_DATE, user.active_at
|
13
|
+
assert user.persisted?
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'creating a model with bang!' do
|
17
|
+
user = create_user!
|
18
|
+
|
19
|
+
assert_equal "The Super User", user.name
|
20
|
+
assert_equal FIXTURE_DATE, user.active_at
|
21
|
+
assert user.persisted?
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'failing to create a model with bang! and invalid attributes' do
|
25
|
+
assert_raise ActiveRecord::RecordInvalid do
|
26
|
+
create_user!(:name => nil)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'do not raise exception when bang is used but not being saved' do
|
31
|
+
assert_nothing_raised do
|
32
|
+
new_user!(:name => nil)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'building a model' do
|
37
|
+
user = new_user
|
38
|
+
|
39
|
+
assert_equal "The Super User", user.name
|
40
|
+
assert_equal FIXTURE_DATE, user.active_at
|
41
|
+
assert user.new_record?
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'generating a hash of attributes' do
|
45
|
+
user_attributes = valid_user_attributes
|
46
|
+
|
47
|
+
assert_equal 'The Super User', user_attributes[:name]
|
48
|
+
assert_equal FIXTURE_DATE, user_attributes[:active_at]
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'respond_to is valid for attributes' do
|
52
|
+
assert respond_to?(:valid_user_attributes)
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'respond_to is valid for builder' do
|
56
|
+
assert respond_to?(:create_user)
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'blocks are lazily evaluated' do
|
60
|
+
user = new_user
|
61
|
+
assert_not_equal user.counter, new_user.counter
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "building new models using a specified class" do
|
66
|
+
test 'create an instance of user' do
|
67
|
+
another_user = new_another_user
|
68
|
+
|
69
|
+
assert_equal 'Another user', another_user.name
|
70
|
+
assert another_user.kind_of?(User)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "building new models" do
|
75
|
+
test 'load a model' do
|
76
|
+
user = create_another_user
|
77
|
+
assert_equal 'Another user', user.name
|
78
|
+
assert_equal FIXTURE_DATE, user.active_at
|
79
|
+
end
|
80
|
+
|
81
|
+
test 'getting its attributes' do
|
82
|
+
user = valid_another_user_attributes
|
83
|
+
assert_equal 'Another user', user[:name]
|
84
|
+
assert_equal FIXTURE_DATE, user[:active_at]
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'respond_to is valid for attributes' do
|
88
|
+
assert respond_to?(:valid_another_user_attributes)
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'respond_to is valid for builder' do
|
92
|
+
assert respond_to?(:create_another_user)
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'respond_to is valid for builder with bang' do
|
96
|
+
assert respond_to?(:create_another_user!)
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'respond_to is valid for builder with new' do
|
100
|
+
assert respond_to?(:new_another_user)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'build models without blocks' do
|
105
|
+
user = create_blockless_user
|
106
|
+
assert user.is_a?(User)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ScopesTest < Hermes::IntegrationCase
|
4
|
+
fixtures :users
|
5
|
+
|
6
|
+
setup do
|
7
|
+
user_a
|
8
|
+
user_b
|
9
|
+
|
10
|
+
visit '/users'
|
11
|
+
end
|
12
|
+
|
13
|
+
test "scope using an active record model" do
|
14
|
+
within user_a do
|
15
|
+
assert has_content?('User A')
|
16
|
+
assert has_no_content?('User B')
|
17
|
+
end
|
18
|
+
|
19
|
+
within user_b do
|
20
|
+
assert has_content?('User B')
|
21
|
+
assert has_no_content?('User A')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
test "scope using implicit css selector" do
|
26
|
+
within 'div#users' do
|
27
|
+
assert has_content?('User A')
|
28
|
+
assert has_content?('User B')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test "scope using declared xpath selector" do
|
33
|
+
within :xpath, "//div[@id='users']" do
|
34
|
+
assert has_content?('User A')
|
35
|
+
assert has_content?('User B')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def user_a
|
41
|
+
@user_a ||= create_user(:name => 'User A')
|
42
|
+
end
|
43
|
+
|
44
|
+
def user_b
|
45
|
+
@user_b ||= create_user(:name => 'User B')
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
RailsApp::Application.load_tasks
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
def index
|
3
|
+
@users = User.all
|
4
|
+
end
|
5
|
+
|
6
|
+
def new
|
7
|
+
@date = params[:date].present?
|
8
|
+
@time = params[:time].present?
|
9
|
+
@datetime = params[:datetime].present? || (!@date && !@time)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
User.create(params[:user])
|
14
|
+
redirect_to users_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def block
|
18
|
+
@user = User.find(params[:id])
|
19
|
+
@user.block!
|
20
|
+
|
21
|
+
redirect_to users_path
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<div id="users">
|
2
|
+
<% @users.each do |user| -%>
|
3
|
+
<%= div_for user do %>
|
4
|
+
<%= user.name %>
|
5
|
+
<%= l(user.active_at) if user.active_at? %>
|
6
|
+
<%= link_to "Block this user", block_user_path(user) %>
|
7
|
+
<% end -%>
|
8
|
+
<% end -%>
|
9
|
+
</div>
|
10
|
+
<%= link_to "New", new_user_url %>
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<%= form_for User.new do |f| %>
|
2
|
+
<ul>
|
3
|
+
<li>
|
4
|
+
<%= f.label :name %>
|
5
|
+
<%= f.text_field :name %>
|
6
|
+
</li>
|
7
|
+
|
8
|
+
<% if @datetime %>
|
9
|
+
<li id="datetime">
|
10
|
+
<%= f.label :active_at %>
|
11
|
+
<%= f.datetime_select :active_at -%>
|
12
|
+
</li>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<% if @time %>
|
16
|
+
<li id="time">
|
17
|
+
<%= f.label :active_at, 'Active at' %>
|
18
|
+
<%= f.time_select :active_at %>
|
19
|
+
</li>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<% if @date %>
|
23
|
+
<li id="date">
|
24
|
+
<%= f.label :active_at, 'Active at' %>
|
25
|
+
<%= f.date_select :active_at %>
|
26
|
+
</li>
|
27
|
+
<% end %>
|
28
|
+
<li>
|
29
|
+
<input type="submit" value="Submit" />
|
30
|
+
</li>
|
31
|
+
|
32
|
+
<li>
|
33
|
+
<label for="useless_select">Useless select</label>
|
34
|
+
<select id="useless_select" name="123">
|
35
|
+
<option value="value1">Value 1</option>
|
36
|
+
<option value="value2">Value 2</option>
|
37
|
+
</select>
|
38
|
+
</li>
|
39
|
+
|
40
|
+
<li>
|
41
|
+
<label for="useless_checkbox">Useless checkbox</label>
|
42
|
+
<input id="useless_checkbox" type="checkbox" checked="checked" />
|
43
|
+
</li>
|
44
|
+
|
45
|
+
<li>
|
46
|
+
<label for="useless_unchecked_checkbox">Useless unchecked checkbox</label>
|
47
|
+
<input id="useless_unchecked_checkbox" type="checkbox"/>
|
48
|
+
</li>
|
49
|
+
</ul>
|
50
|
+
<% end -%>
|
51
|
+
|
52
|
+
<table id="useless_table">
|
53
|
+
<caption>Useless Table</caption>
|
54
|
+
<tr>
|
55
|
+
<td>Cuba Pete</td>
|
56
|
+
<td>King of the Ramba beat</td>
|
57
|
+
</tr>
|
58
|
+
<tr>
|
59
|
+
<td>Lou Bega</td>
|
60
|
+
<td>Mambo No. 5</td>
|
61
|
+
</tr>
|
62
|
+
</table>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "active_model/railtie"
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_view/railtie"
|
7
|
+
require "action_mailer/railtie"
|
8
|
+
|
9
|
+
module RailsApp
|
10
|
+
class Application < Rails::Application
|
11
|
+
# Settings in config/environments/* take precedence over those specified here.
|
12
|
+
# Application configuration should go into files in config/initializers
|
13
|
+
# -- all .rb files in that directory are automatically loaded.
|
14
|
+
|
15
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
16
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
17
|
+
|
18
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
19
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
20
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
21
|
+
|
22
|
+
# Activate observers that should always be running.
|
23
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
24
|
+
|
25
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
26
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
27
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
28
|
+
|
29
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
30
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
31
|
+
# config.i18n.default_locale = :de
|
32
|
+
|
33
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
34
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
35
|
+
|
36
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
37
|
+
config.encoding = "utf-8"
|
38
|
+
|
39
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
40
|
+
config.filter_parameters += [:password]
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: ":memory:"
|
15
|
+
|
16
|
+
production:
|
17
|
+
adapter: sqlite3
|
18
|
+
database: db/production.sqlite3
|
19
|
+
pool: 5
|
20
|
+
timeout: 5000
|
@@ -0,0 +1,26 @@
|
|
1
|
+
RailsApp::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
RailsApp::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|