test_rails_js 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,8 +10,15 @@ class JsTestsController < ActionController::Base
10
10
  private
11
11
  def tests
12
12
  @tests ||= Rails.application.config.assets.paths.inject([]){ |tests, path|
13
- tests + Dir[path + "/*_tests.js"]
14
- }.map{ |path| Pathname(path).basename('.js').to_s }
13
+ asset_path = Pathname(path)
14
+ tests + (
15
+ Dir[path + "/*_tests.js"] +
16
+ Dir[path + "/tests/**/*.js"]
17
+ ).map{ |test|
18
+ { :asset => Pathname(test).relative_path_from(asset_path).sub_ext('').to_s,
19
+ :path => Pathname(test).relative_path_from(Rails.root) }
20
+ }
21
+ }
15
22
  end
16
23
 
17
24
  def test
@@ -0,0 +1,17 @@
1
+ module JsTestsHelper
2
+ def global_assets
3
+ Rails.application.config.test_rails_js.global_assets
4
+ end
5
+
6
+ def tests_by_path
7
+ tests.inject({}) do |acc, test|
8
+ node = acc
9
+ path, test_name = test[:path].split
10
+ path.each_filename do |name|
11
+ node = (node[name] ||= {})
12
+ end
13
+ node[test_name.to_s] = test[:asset]
14
+ acc
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ <% tests.each do |path, tests| %>
2
+ <% if tests.is_a? Hash %>
3
+ <dd>
4
+ <dl>
5
+ <dt><%= path %></dt>
6
+ <%= render :partial => 'tests', :locals => { :tests => tests } %>
7
+ </dl>
8
+ </dd>
9
+ <% else %>
10
+ <dd><%= link_to path, main_app.js_test_path(tests) %></dd>
11
+ <% end %>
12
+ <% end %>
@@ -1,11 +1,16 @@
1
1
  <html>
2
2
  <head>
3
+ <title>Test Rails JS</title>
4
+ <style>
5
+ body { line-height: 1.2; }
6
+ dl, dt, dd { margin: 0; padding: 0; }
7
+ body > dd > dl { margin-bottom: 1em; }
8
+ dl > dd { padding-left: 1em; }
9
+ </style>
3
10
  </head>
4
11
  <body>
5
- <ul>
6
- <% tests.each do |test| %>
7
- <li><%= link_to test, main_app.js_test_path(test) %></li>
8
- <% end %>
9
- </ul>
12
+ <% tests_by_path.each do |path, tests| %>
13
+ <%= render :partial => 'tests', :locals => { :tests => tests } %>
14
+ <% end %>
10
15
  </body>
11
16
  </html>
@@ -1,8 +1,15 @@
1
1
  <html>
2
2
  <head>
3
+ <title><%= test %> - Test Rails JS</title>
4
+ <% global_assets.stylesheets.each do |asset| %>
5
+ <%= stylesheet_link_tag asset %>
6
+ <% end %>
3
7
  <%= stylesheet_link_tag test %>
4
8
  </head>
5
9
  <body>
10
+ <% global_assets.javascripts.each do |asset| %>
11
+ <%= javascript_include_tag asset %>
12
+ <% end %>
6
13
  <%= javascript_include_tag test %>
7
14
  </body>
8
15
  </html>
data/config/routes.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  Rails.application.routes.draw do
2
- resources :js_tests, :only => [ :index, :show ]
2
+ match '/js_tests' => 'js_tests#index', :as => :js_tests
3
+ match '/js_tests/*id' => 'js_tests#show', :as => :js_test
3
4
  end
@@ -1,3 +1,3 @@
1
1
  module TestRailsJs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/test_rails_js.rb CHANGED
@@ -2,4 +2,15 @@ module TestRailsJs
2
2
  class Engine < Rails::Engine
3
3
  engine_name "test_rails_js"
4
4
  end
5
+
6
+ class Railtie < ::Rails::Railtie
7
+ module TestRailsJsContext
8
+ attr_accessor :test_rails_js_config
9
+ end
10
+
11
+ config.test_rails_js = ActiveSupport::OrderedOptions.new
12
+ config.test_rails_js.global_assets = ActiveSupport::OrderedOptions.new
13
+ config.test_rails_js.global_assets.javascripts = []
14
+ config.test_rails_js.global_assets.stylesheets = []
15
+ end
5
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_rails_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-09 00:00:00.000000000 -05:00
12
+ date: 2011-09-12 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &74412260 !ruby/object:Gem::Requirement
17
+ requirement: &84479880 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *74412260
25
+ version_requirements: *84479880
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sqlite3
28
- requirement: &74411990 !ruby/object:Gem::Requirement
28
+ requirement: &84479650 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *74411990
36
+ version_requirements: *84479650
37
37
  description: Test your rails JS in-browser.
38
38
  email:
39
39
  - Douglas.Meyer@Centro.net
@@ -43,7 +43,9 @@ extra_rdoc_files: []
43
43
  files:
44
44
  - app/views/js_tests/index.html.erb
45
45
  - app/views/js_tests/show.html.erb
46
+ - app/views/js_tests/_tests.html.erb
46
47
  - app/controllers/js_tests_controller.rb
48
+ - app/helpers/js_tests_helper.rb
47
49
  - config/routes.rb
48
50
  - lib/test_rails_js/version.rb
49
51
  - lib/test_rails_js.rb