reactive-ruby 0.7.22 → 0.7.23

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +102 -21
  6. data/README.md +5 -0
  7. data/Rakefile +18 -0
  8. data/lib/generators/reactive_ruby/test_app/templates/application.rb +11 -0
  9. data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/application.rb +2 -0
  10. data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +3 -0
  11. data/lib/generators/reactive_ruby/test_app/templates/boot.rb +6 -0
  12. data/lib/generators/reactive_ruby/test_app/templates/script/rails +5 -0
  13. data/lib/generators/reactive_ruby/test_app/test_app_generator.rb +101 -0
  14. data/lib/rails-helpers/react_component.rb +4 -3
  15. data/lib/reactive-ruby.rb +1 -1
  16. data/lib/reactive-ruby/component.rb +1 -1
  17. data/lib/reactive-ruby/state.rb +11 -7
  18. data/lib/reactive-ruby/version.rb +1 -1
  19. data/{spec → opal-spec}/callbacks_spec.rb +0 -0
  20. data/{spec → opal-spec}/component_spec.rb +0 -0
  21. data/{spec → opal-spec}/element_spec.rb +0 -0
  22. data/{spec → opal-spec}/event_spec.rb +0 -0
  23. data/{spec → opal-spec}/react_spec.rb +0 -0
  24. data/{spec → opal-spec}/reactjs/index.html.erb +1 -1
  25. data/opal-spec/spec_helper.rb +29 -0
  26. data/{spec → opal-spec}/tutorial/tutorial_spec.rb +0 -0
  27. data/{spec → opal-spec}/validator_spec.rb +0 -0
  28. data/reactive-ruby.gemspec +9 -4
  29. data/spec/controller_helper_spec.rb +20 -0
  30. data/spec/react/rails/view_helper_spec.rb +53 -0
  31. data/spec/spec_helper.rb +22 -22
  32. metadata +81 -25
  33. data/vendor/active_support/core_ext/array/extract_options.rb +0 -29
  34. data/vendor/active_support/core_ext/class/attribute.rb +0 -127
  35. data/vendor/active_support/core_ext/kernel/singleton_class.rb +0 -13
  36. data/vendor/active_support/core_ext/module/remove_method.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15360936fd9c8c7e462b51ccc66443166cd996e5
4
- data.tar.gz: ba65ae66afb0a47a3bea2d5ea820334069ef9990
3
+ metadata.gz: 07287ee1cef383b6be9138dddaf7241b7c5f13ca
4
+ data.tar.gz: 8d71d2136f76dc0a7b51069c568715da6d1b4640
5
5
  SHA512:
6
- metadata.gz: 62ee588744392b770eca423be2bd69d5e1f5fc695b4e24c22db94306cf61dd4a45ca1989f2a86ab5a19c678061d521d320470528af4d9a208a0911211cdd56e8
7
- data.tar.gz: 5f6c17de0abdbad82eb96f34ddfe0d4c46a9ff1b37c5cedd335c9deaad26fcd7a7eef7ea138086c6da40b8fac56a8d20ddbd443ec2e99091a938f7676a8c6500
6
+ metadata.gz: 630e32da18390106e2aa6e9b17a86c5ffdde5f20fa1c6a0401c12255845c11ee0f014ab81aa4ef4d0e392ea2c2cc71a0f7e82ccbcc11ec15c497fd2b72a98da2
7
+ data.tar.gz: ee3293d87ef084eda0e9a31518a804d9fd0cbdeaf4bd3436edc808c3ecc96a376dde584bcf390e3afb746c568e48a84ccc65f54ca94691cedc6206c48a2a487b
data/.gitignore CHANGED
@@ -28,3 +28,5 @@ node_modules
28
28
 
29
29
  # Ignore bundler config.
30
30
  .bundle
31
+
32
+ spec/test_app
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
data/Gemfile CHANGED
@@ -1,2 +1,5 @@
1
1
  source 'https://rubygems.org'
2
+ group :development, :test do
3
+ gem 'react-rails', github: 'catprintlabs/react-rails', branch: 'isomorphic-methods-support'
4
+ end
2
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,47 +1,84 @@
1
+ GIT
2
+ remote: git://github.com/catprintlabs/react-rails.git
3
+ revision: 98a8d903a51065c8e3ffedeb094d72a2e9883176
4
+ branch: isomorphic-methods-support
5
+ specs:
6
+ react-rails (1.0.0)
7
+ coffee-script-source (~> 1.8)
8
+ connection_pool
9
+ execjs
10
+ rails (>= 3.2)
11
+ tilt
12
+
1
13
  PATH
2
14
  remote: .
3
15
  specs:
4
- reactive-ruby (0.7.5)
5
- jquery-rails
16
+ reactive-ruby (0.7.21)
6
17
  opal
7
- opal-activesupport
18
+ opal-activesupport (>= 0.2.0)
8
19
  opal-browser
9
20
 
10
21
  GEM
11
22
  remote: https://rubygems.org/
12
23
  specs:
13
- actionpack (4.2.3)
14
- actionview (= 4.2.3)
15
- activesupport (= 4.2.3)
24
+ actionmailer (4.2.4)
25
+ actionpack (= 4.2.4)
26
+ actionview (= 4.2.4)
27
+ activejob (= 4.2.4)
28
+ mail (~> 2.5, >= 2.5.4)
29
+ rails-dom-testing (~> 1.0, >= 1.0.5)
30
+ actionpack (4.2.4)
31
+ actionview (= 4.2.4)
32
+ activesupport (= 4.2.4)
16
33
  rack (~> 1.6)
17
34
  rack-test (~> 0.6.2)
18
35
  rails-dom-testing (~> 1.0, >= 1.0.5)
19
36
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
20
- actionview (4.2.3)
21
- activesupport (= 4.2.3)
37
+ actionview (4.2.4)
38
+ activesupport (= 4.2.4)
22
39
  builder (~> 3.1)
23
40
  erubis (~> 2.7.0)
24
41
  rails-dom-testing (~> 1.0, >= 1.0.5)
25
42
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
26
- activesupport (4.2.3)
43
+ activejob (4.2.4)
44
+ activesupport (= 4.2.4)
45
+ globalid (>= 0.3.0)
46
+ activemodel (4.2.4)
47
+ activesupport (= 4.2.4)
48
+ builder (~> 3.1)
49
+ activerecord (4.2.4)
50
+ activemodel (= 4.2.4)
51
+ activesupport (= 4.2.4)
52
+ arel (~> 6.0)
53
+ activesupport (4.2.4)
27
54
  i18n (~> 0.7)
28
55
  json (~> 1.7, >= 1.7.7)
29
56
  minitest (~> 5.1)
30
57
  thread_safe (~> 0.3, >= 0.3.4)
31
58
  tzinfo (~> 1.1)
59
+ arel (6.0.3)
32
60
  builder (3.2.2)
61
+ coffee-script-source (1.9.1.1)
62
+ connection_pool (2.2.0)
63
+ diff-lcs (1.2.5)
33
64
  erubis (2.7.0)
65
+ execjs (2.6.0)
66
+ globalid (0.3.6)
67
+ activesupport (>= 4.1.0)
34
68
  hike (1.2.3)
35
69
  i18n (0.7.0)
36
- jquery-rails (4.0.4)
70
+ jquery-rails (4.0.5)
37
71
  rails-dom-testing (~> 1.0)
38
72
  railties (>= 4.2.0)
39
73
  thor (>= 0.14, < 2.0)
40
74
  json (1.8.3)
41
75
  loofah (2.0.3)
42
76
  nokogiri (>= 1.5.9)
77
+ mail (2.6.3)
78
+ mime-types (>= 1.16, < 3)
79
+ mime-types (2.6.2)
43
80
  mini_portile (0.6.2)
44
- minitest (5.8.0)
81
+ minitest (5.8.1)
45
82
  nokogiri (1.6.6.2)
46
83
  mini_portile (~> 0.6.0)
47
84
  opal (0.8.0)
@@ -49,19 +86,39 @@ GEM
49
86
  sourcemap (~> 0.1.0)
50
87
  sprockets (~> 3.1)
51
88
  tilt (>= 1.4)
52
- opal-activesupport (0.1.0)
89
+ opal-activesupport (0.2.0)
53
90
  opal (>= 0.5.0, < 1.0.0)
54
91
  opal-browser (0.2.0)
55
92
  opal
56
93
  paggio
94
+ opal-jquery (0.4.0)
95
+ opal (>= 0.7.0, < 0.9.0)
96
+ opal-rails (0.8.0)
97
+ jquery-rails
98
+ opal (~> 0.8.0)
99
+ opal-activesupport (>= 0.0.5)
100
+ opal-jquery (~> 0.4.0)
101
+ opal-rspec (~> 0.4.3)
102
+ rails (>= 3.2, < 5.0)
57
103
  opal-rspec (0.4.3)
58
104
  opal (>= 0.7.0, < 0.9)
59
- paggio (0.2.4)
105
+ paggio (0.2.5)
60
106
  rack (1.6.4)
61
107
  rack-protection (1.5.3)
62
108
  rack
63
109
  rack-test (0.6.3)
64
110
  rack (>= 1.0)
111
+ rails (4.2.4)
112
+ actionmailer (= 4.2.4)
113
+ actionpack (= 4.2.4)
114
+ actionview (= 4.2.4)
115
+ activejob (= 4.2.4)
116
+ activemodel (= 4.2.4)
117
+ activerecord (= 4.2.4)
118
+ activesupport (= 4.2.4)
119
+ bundler (>= 1.3.0, < 2.0)
120
+ railties (= 4.2.4)
121
+ sprockets-rails
65
122
  rails-deprecated_sanitizer (1.0.3)
66
123
  activesupport (>= 4.2.0.alpha)
67
124
  rails-dom-testing (1.0.7)
@@ -70,19 +127,41 @@ GEM
70
127
  rails-deprecated_sanitizer (>= 1.0.1)
71
128
  rails-html-sanitizer (1.0.2)
72
129
  loofah (~> 2.0)
73
- railties (4.2.3)
74
- actionpack (= 4.2.3)
75
- activesupport (= 4.2.3)
130
+ railties (4.2.4)
131
+ actionpack (= 4.2.4)
132
+ activesupport (= 4.2.4)
76
133
  rake (>= 0.8.7)
77
134
  thor (>= 0.18.1, < 2.0)
78
135
  rake (10.4.2)
136
+ rspec-core (3.3.2)
137
+ rspec-support (~> 3.3.0)
138
+ rspec-expectations (3.3.1)
139
+ diff-lcs (>= 1.2.0, < 2.0)
140
+ rspec-support (~> 3.3.0)
141
+ rspec-mocks (3.3.2)
142
+ diff-lcs (>= 1.2.0, < 2.0)
143
+ rspec-support (~> 3.3.0)
144
+ rspec-rails (3.3.3)
145
+ actionpack (>= 3.0, < 4.3)
146
+ activesupport (>= 3.0, < 4.3)
147
+ railties (>= 3.0, < 4.3)
148
+ rspec-core (~> 3.3.0)
149
+ rspec-expectations (~> 3.3.0)
150
+ rspec-mocks (~> 3.3.0)
151
+ rspec-support (~> 3.3.0)
152
+ rspec-support (3.3.0)
79
153
  sinatra (1.4.6)
80
154
  rack (~> 1.4)
81
155
  rack-protection (~> 1.4)
82
156
  tilt (>= 1.3, < 3)
83
157
  sourcemap (0.1.1)
84
- sprockets (3.3.3)
85
- rack (~> 1.0)
158
+ sprockets (3.4.0)
159
+ rack (> 1, < 3)
160
+ sprockets-rails (2.3.3)
161
+ actionpack (>= 3.0)
162
+ activesupport (>= 3.0)
163
+ sprockets (>= 2.8, < 4.0)
164
+ sqlite3 (1.3.10)
86
165
  thor (0.19.1)
87
166
  thread_safe (0.3.5)
88
167
  tilt (2.0.1)
@@ -93,9 +172,11 @@ PLATFORMS
93
172
  ruby
94
173
 
95
174
  DEPENDENCIES
175
+ opal-rails
96
176
  opal-rspec
177
+ rake
178
+ react-rails!
97
179
  reactive-ruby!
180
+ rspec-rails
98
181
  sinatra
99
-
100
- BUNDLED WITH
101
- 1.10.6
182
+ sqlite3
data/README.md CHANGED
@@ -156,6 +156,11 @@ To run the above examples project yourself:
156
156
  3. `bundle exec rackup`
157
157
  4. Open `http://localhost`
158
158
 
159
+ ## Testing
160
+
161
+ 1. Run `bundle exec rake test_app` to generate a dummy test app.
162
+ 2. `bundle exec rspec`
163
+
159
164
  ## Contributions
160
165
 
161
166
  This project is still in early stage, so discussion, bug report and PR are really welcome :wink:.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ task default: :spec
9
+ rescue LoadError
10
+ end
11
+
12
+ require 'generators/reactive_ruby/test_app/test_app_generator'
13
+ desc "Generates a dummy app for testing"
14
+ task :test_app do
15
+ ReactiveRuby::TestAppGenerator.start
16
+ puts "Setting up test app database..."
17
+ system("bundle exec rake db:drop db:create db:migrate > #{File::NULL}")
18
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # Require the gems listed in Gemfile, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(*Rails.groups(assets: %w(development test)))
8
+
9
+ require 'reactive-ruby'
10
+
11
+ <%= application_definition %>
@@ -0,0 +1,2 @@
1
+ require 'components'
2
+ require 'react_ujs'
@@ -0,0 +1,3 @@
1
+ require 'opal'
2
+ require 'reactive-ruby'
3
+ require_tree './components'
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path("<%= gemfile_path %>", __FILE__)
3
+
4
+ ENV['BUNDLE_GEMFILE'] = gemfile
5
+ require 'bundler'
6
+ Bundler.setup
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
4
+ require File.expand_path('../../config/boot', __FILE__)
5
+ require 'rails/commands'
@@ -0,0 +1,101 @@
1
+ require 'rails/generators/rails/app/app_generator'
2
+
3
+ module ReactiveRuby
4
+ class TestAppGenerator < Rails::Generators::Base
5
+ def self.source_paths
6
+ paths = self.superclass.source_paths
7
+ paths << File.expand_path('../templates', __FILE__)
8
+ paths.flatten
9
+ end
10
+
11
+ def remove_existing_app
12
+ remove_dir(test_app_path) if File.directory?(test_app_path)
13
+ end
14
+
15
+ def generate_test_app
16
+ opts = options.dup
17
+ opts[:database] = 'sqlite3' if opts[:database].blank?
18
+ opts[:force] = true
19
+ opts[:skip_bundle] = true
20
+
21
+ puts "Generating Test Rails Application..."
22
+ invoke Rails::Generators::AppGenerator,
23
+ [ File.expand_path(test_app_path, destination_root) ], opts
24
+ end
25
+
26
+ def configure_test_app
27
+ template 'boot.rb', "#{test_app_path}/config/boot.rb", force: true
28
+ template 'application.rb', "#{test_app_path}/config/application.rb", force: true
29
+ template 'assets/javascripts/application.rb',
30
+ "#{test_app_path}/app/assets/javascripts/application.rb", force: true
31
+ template 'assets/javascripts/components.rb',
32
+ "#{test_app_path}/app/views/components.rb", force: true
33
+ end
34
+
35
+ def clean_superfluous_files
36
+ inside test_app_path do
37
+ remove_file '.gitignore'
38
+ remove_file 'doc'
39
+ remove_file 'Gemfile'
40
+ remove_file 'lib/tasks'
41
+ remove_file 'app/assets/images/rails.png'
42
+ remove_file 'app/assets/javascripts/application.js'
43
+ remove_file 'public/index.html'
44
+ remove_file 'public/robots.txt'
45
+ remove_file 'README.rdoc'
46
+ remove_file 'test'
47
+ remove_file 'vendor'
48
+ remove_file 'spec'
49
+ end
50
+ end
51
+
52
+ def configure_opal_rspec
53
+ inject_into_file "#{test_app_path}/config/application.rb",
54
+ after: /class Application < Rails::Application/, verbose: true do
55
+ %Q[
56
+ config.opal.method_missing = true
57
+ config.opal.optimized_operators = true
58
+ config.opal.arity_check = false
59
+ config.opal.const_missing = true
60
+ config.opal.dynamic_require_severity = :ignore
61
+ config.opal.enable_specs = true
62
+ config.opal.spec_location = 'spec-opal'
63
+ ]
64
+ end
65
+ end
66
+
67
+ protected
68
+
69
+ def application_definition
70
+ @application_definition ||= begin
71
+ test_application_contents
72
+ end
73
+ end
74
+ alias :store_application_definition! :application_definition
75
+
76
+ private
77
+
78
+ def test_app_path
79
+ 'spec/test_app'
80
+ end
81
+
82
+ def test_application_path
83
+ File.expand_path("#{test_app_path}/config/application.rb",
84
+ destination_root)
85
+ end
86
+
87
+ def test_application_contents
88
+ return unless File.exists?(test_application_path) && !options[:pretend]
89
+ contents = File.read(test_application_path)
90
+ contents[(contents.index("module #{module_name}"))..-1]
91
+ end
92
+
93
+ def module_name
94
+ 'TestApp'
95
+ end
96
+
97
+ def gemfile_path
98
+ '../../../../Gemfile'
99
+ end
100
+ end
101
+ end
@@ -1,5 +1,6 @@
1
1
  begin
2
2
 
3
+ require 'action_controller'
3
4
  require 'react-rails'
4
5
  require 'reactive-ruby'
5
6
 
@@ -16,9 +17,9 @@ begin
16
17
  module React
17
18
 
18
19
  class Railtie < ::Rails::Railtie
19
- config.before_configuration do
20
- config.assets.enabled = true
21
- config.assets.paths << ::Rails.root.join('app', 'views').to_s
20
+ config.before_configuration do |app|
21
+ app.config.assets.enabled = true
22
+ app.config.assets.paths << ::Rails.root.join('app', 'views').to_s
22
23
  end
23
24
  end
24
25
 
data/lib/reactive-ruby.rb CHANGED
@@ -15,6 +15,7 @@ if RUBY_ENGINE == 'opal'
15
15
 
16
16
  else
17
17
  require "opal"
18
+ require "opal-rails"
18
19
  require "opal-browser"
19
20
  require "reactive-ruby/version"
20
21
  require "opal-activesupport"
@@ -23,5 +24,4 @@ else
23
24
  require "reactive-ruby/serializers"
24
25
 
25
26
  Opal.append_path File.expand_path('../', __FILE__).untaint
26
- Opal.append_path File.expand_path('../../vendor', __FILE__).untaint
27
27
  end
@@ -28,7 +28,7 @@ module React
28
28
  end unless method_defined? :render
29
29
 
30
30
  def children
31
- nodes = `#{@native}.props.children` || []
31
+ nodes = [`#{@native}.props.children`].flatten
32
32
  class << nodes
33
33
  include Enumerable
34
34
 
@@ -22,14 +22,18 @@ module React
22
22
  end
23
23
  end
24
24
 
25
- def set_state(object, name, value)
25
+ def set_state(object, name, value, delay=nil)
26
26
  states[object][name] = value
27
- if name == "!CHANGED!" and @current_observer
28
- #puts "changing !CHANGED! to #{value} with a current observer - actual change will be delayed"
29
- after(0.01) do
30
- value = "#{value}@#{Time.now}"
31
- #puts "NOW setting !CHANGED! to #{value}"
32
- set_state2(object, name, value)
27
+ if delay
28
+ @delayed_updates ||= []
29
+ @delayed_updates << [object, name, value]
30
+ @delayed_updater ||= after(0.001) do
31
+ delayed_updates = @delayed_updates
32
+ @delayed_updates = []
33
+ @delayed_updater = nil
34
+ delayed_updates.each do |object, name, value|
35
+ set_state2(object, name, value)
36
+ end
33
37
  end
34
38
  else
35
39
  set_state2(object, name, value)
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = "0.7.22"
2
+ VERSION = "0.7.23"
3
3
  end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  </head>
5
5
  <body>
6
- <%= javascript_include_tag 'react-with-addons' %>
6
+ <%= javascript_include_tag 'react' %>
7
7
  <%= javascript_include_tag @server.main %>
8
8
  <div id="placeholder" style="display: none"></div>
9
9
  <div id="render_here"></div>
@@ -0,0 +1,29 @@
1
+ require 'react'
2
+
3
+ module ReactTestHelpers
4
+ `var ReactTestUtils = React.addons.TestUtils`
5
+
6
+ def renderToDocument(type, options = {})
7
+ element = React.create_element(type, options)
8
+ return renderElementToDocument(element)
9
+ end
10
+
11
+ def renderElementToDocument(element)
12
+ instance = Native(`ReactTestUtils.renderIntoDocument(#{element.to_n})`)
13
+ instance.class.include(React::Component::API)
14
+ return instance
15
+ end
16
+
17
+ def simulateEvent(event, element, params = {})
18
+ simulator = Native(`ReactTestUtils.Simulate`)
19
+ simulator[event.to_s].call(`#{element.to_n}.getDOMNode()`, params)
20
+ end
21
+
22
+ def isElementOfType(element, type)
23
+ `React.addons.TestUtils.isElementOfType(#{element.to_n}, #{type.cached_component_class})`
24
+ end
25
+ end
26
+
27
+ RSpec.configure do |config|
28
+ config.include ReactTestHelpers
29
+ end
File without changes
File without changes
@@ -16,11 +16,16 @@ Gem::Specification.new do |s|
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.require_paths = ['lib', 'vendor']
19
+ s.require_paths = ['lib']
20
20
 
21
- s.add_runtime_dependency 'opal'
22
- s.add_runtime_dependency 'opal-activesupport'
23
- s.add_runtime_dependency 'opal-browser'
21
+
22
+ s.add_dependency 'opal'
23
+ s.add_dependency 'opal-activesupport', '>= 0.2.0'
24
+ s.add_dependency 'opal-browser'
25
+ s.add_development_dependency 'opal-rails'
26
+ s.add_development_dependency 'rake'
27
+ s.add_development_dependency 'rspec-rails'
24
28
  s.add_development_dependency 'opal-rspec'
25
29
  s.add_development_dependency 'sinatra'
30
+ s.add_development_dependency 'sqlite3' # For Test Rails App
26
31
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ class TestController < ActionController::Base; end
4
+
5
+ RSpec.describe TestController, type: :controller do
6
+ render_views
7
+
8
+ describe '#render_component' do
9
+ controller do
10
+ def index
11
+ render_component
12
+ end
13
+ end
14
+
15
+ it 'renders the application layout' do
16
+ get :index, no_prerender: true
17
+ expect(response).to render_template(layout: :application)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe React::Rails::ViewHelper, type: :helper do
4
+ describe '#react_component' do
5
+ it 'renders a div' do
6
+ html = helper.react_component('Components::HelloWorld')
7
+ expect(html).to match(/<div.*><\/div>/)
8
+ end
9
+
10
+ it 'sets data-react-class to React.TopLevelRailsComponent' do
11
+ html = helper.react_component('Components::HelloWorld')
12
+ top_level_class = 'React.TopLevelRailsComponent'
13
+ expect(attr_value(html, 'data-react-class')).to eq(top_level_class)
14
+ end
15
+
16
+ it 'sets component_name in data-react-props hash' do
17
+ html = helper.react_component('Components::HelloWorld')
18
+ props = react_props_for(html)
19
+
20
+ expect(props['component_name']).to eq('Components::HelloWorld')
21
+ end
22
+
23
+ it 'sets render_params in data-react-props hash' do
24
+ html = helper.react_component('Components::HelloWorld', {'foo' => 'bar'})
25
+ props = react_props_for(html)
26
+
27
+ expect(props['render_params']).to include({ 'foo' => 'bar' })
28
+ end
29
+
30
+ it 'sets controller in data-react-props hash' do
31
+ html = helper.react_component('Components::HelloWorld')
32
+ props = react_props_for(html)
33
+
34
+ expect(props['controller']).to eq('ActionView::TestCase::TestController')
35
+ end
36
+
37
+ it 'passes additional options through as html attributes' do
38
+ html = helper.react_component('Components::HelloWorld', {},
39
+ { 'foo-bar' => 'biz-baz' })
40
+
41
+ expect(attr_value(html, 'foo-bar')).to eq('biz-baz')
42
+ end
43
+ end
44
+
45
+ def attr_value(html, attr)
46
+ matches = html.match(/#{attr}=["']((?:.(?!["']\s+(?:\S+)=|[>"']))+.)["']?/)
47
+ matches.captures.first
48
+ end
49
+
50
+ def react_props_for(html)
51
+ JSON.parse(CGI.unescapeHTML("#{attr_value(html, 'data-react-props')}"))
52
+ end
53
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,29 +1,29 @@
1
- require 'react'
1
+ ENV["RAILS_ENV"] ||= 'test'
2
2
 
3
- module ReactTestHelpers
4
- `var ReactTestUtils = React.addons.TestUtils`
3
+ begin
4
+ require File.expand_path('../test_app/config/environment', __FILE__)
5
+ rescue LoadError
6
+ puts 'Could not load test application. Please ensure you have run `bundle exec rake test_app`'
7
+ end
5
8
 
6
- def renderToDocument(type, options = {})
7
- element = React.create_element(type, options)
8
- return renderElementToDocument(element)
9
- end
9
+ require 'rspec/rails'
10
10
 
11
- def renderElementToDocument(element)
12
- instance = Native(`ReactTestUtils.renderIntoDocument(#{element.to_n})`)
13
- instance.class.include(React::Component::API)
14
- return instance
15
- end
11
+ Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
16
12
 
17
- def simulateEvent(event, element, params = {})
18
- simulator = Native(`ReactTestUtils.Simulate`)
19
- simulator[event.to_s].call(`#{element.to_n}.getDOMNode()`, params)
20
- end
13
+ RSpec.configure do |config|
14
+ config.color = true
15
+ config.fail_fast = ENV['FAIL_FAST'] || false
16
+ config.fixture_path = File.join(File.expand_path(File.dirname(__FILE__)), "fixtures")
17
+ config.infer_spec_type_from_file_location!
18
+ config.mock_with :rspec
19
+ config.raise_errors_for_deprecations!
21
20
 
22
- def isElementOfType(element, type)
23
- `React.addons.TestUtils.isElementOfType(#{element.to_n}, #{type.cached_component_class})`
24
- end
25
- end
21
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
22
+ # examples within a transaction, comment the following line or assign false
23
+ # instead of true.
24
+ config.use_transactional_fixtures = true
26
25
 
27
- RSpec.configure do |config|
28
- config.include ReactTestHelpers
26
+ config.before :each do
27
+ Rails.cache.clear
28
+ end
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.22
4
+ version: 0.7.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-02 00:00:00.000000000 Z
11
+ date: 2015-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: opal-browser
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: opal-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: opal-rspec
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +122,20 @@ dependencies:
80
122
  - - ">="
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
83
139
  description: Write reactive UI component with Ruby's elegancy and compiled to run
84
140
  in Javascript.
85
141
  email: zeta11235813@gmail.com
@@ -88,10 +144,12 @@ extensions: []
88
144
  extra_rdoc_files: []
89
145
  files:
90
146
  - ".gitignore"
147
+ - ".travis.yml"
91
148
  - Gemfile
92
149
  - Gemfile.lock
93
150
  - LICENSE
94
151
  - README.md
152
+ - Rakefile
95
153
  - config.ru
96
154
  - example/examples/Gemfile
97
155
  - example/examples/Gemfile.lock
@@ -188,6 +246,12 @@ files:
188
246
  - example/todos/vendor/base.css
189
247
  - example/todos/vendor/bg.png
190
248
  - example/todos/vendor/jquery.js
249
+ - lib/generators/reactive_ruby/test_app/templates/application.rb
250
+ - lib/generators/reactive_ruby/test_app/templates/assets/javascripts/application.rb
251
+ - lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb
252
+ - lib/generators/reactive_ruby/test_app/templates/boot.rb
253
+ - lib/generators/reactive_ruby/test_app/templates/script/rails
254
+ - lib/generators/reactive_ruby/test_app/test_app_generator.rb
191
255
  - lib/rails-helpers/react_component.rb
192
256
  - lib/rails-helpers/top_level_rails_component.rb
193
257
  - lib/reactive-ruby.rb
@@ -212,20 +276,19 @@ files:
212
276
  - logo2.png
213
277
  - logo3.png
214
278
  - old-readme
279
+ - opal-spec/callbacks_spec.rb
280
+ - opal-spec/component_spec.rb
281
+ - opal-spec/element_spec.rb
282
+ - opal-spec/event_spec.rb
283
+ - opal-spec/react_spec.rb
284
+ - opal-spec/reactjs/index.html.erb
285
+ - opal-spec/spec_helper.rb
286
+ - opal-spec/tutorial/tutorial_spec.rb
287
+ - opal-spec/validator_spec.rb
215
288
  - reactive-ruby.gemspec
216
- - spec/callbacks_spec.rb
217
- - spec/component_spec.rb
218
- - spec/element_spec.rb
219
- - spec/event_spec.rb
220
- - spec/react_spec.rb
221
- - spec/reactjs/index.html.erb
289
+ - spec/controller_helper_spec.rb
290
+ - spec/react/rails/view_helper_spec.rb
222
291
  - spec/spec_helper.rb
223
- - spec/tutorial/tutorial_spec.rb
224
- - spec/validator_spec.rb
225
- - vendor/active_support/core_ext/array/extract_options.rb
226
- - vendor/active_support/core_ext/class/attribute.rb
227
- - vendor/active_support/core_ext/kernel/singleton_class.rb
228
- - vendor/active_support/core_ext/module/remove_method.rb
229
292
  homepage: https://github.com/zetachang/react.rb
230
293
  licenses:
231
294
  - MIT
@@ -234,7 +297,6 @@ post_install_message:
234
297
  rdoc_options: []
235
298
  require_paths:
236
299
  - lib
237
- - vendor
238
300
  required_ruby_version: !ruby/object:Gem::Requirement
239
301
  requirements:
240
302
  - - ">="
@@ -252,12 +314,6 @@ signing_key:
252
314
  specification_version: 4
253
315
  summary: Opal Ruby wrapper of React.js library.
254
316
  test_files:
255
- - spec/callbacks_spec.rb
256
- - spec/component_spec.rb
257
- - spec/element_spec.rb
258
- - spec/event_spec.rb
259
- - spec/react_spec.rb
260
- - spec/reactjs/index.html.erb
317
+ - spec/controller_helper_spec.rb
318
+ - spec/react/rails/view_helper_spec.rb
261
319
  - spec/spec_helper.rb
262
- - spec/tutorial/tutorial_spec.rb
263
- - spec/validator_spec.rb
@@ -1,29 +0,0 @@
1
- class Hash
2
- # By default, only instances of Hash itself are extractable.
3
- # Subclasses of Hash may implement this method and return
4
- # true to declare themselves as extractable. If a Hash
5
- # is extractable, Array#extract_options! pops it from
6
- # the Array when it is the last element of the Array.
7
- def extractable_options?
8
- instance_of?(Hash)
9
- end
10
- end
11
-
12
- class Array
13
- # Extracts options from a set of arguments. Removes and returns the last
14
- # element in the array if it's a hash, otherwise returns a blank hash.
15
- #
16
- # def options(*args)
17
- # args.extract_options!
18
- # end
19
- #
20
- # options(1, 2) # => {}
21
- # options(1, 2, :a => :b) # => {:a=>:b}
22
- def extract_options!
23
- if last.is_a?(Hash) && last.extractable_options?
24
- pop
25
- else
26
- {}
27
- end
28
- end
29
- end
@@ -1,127 +0,0 @@
1
- require 'active_support/core_ext/kernel/singleton_class'
2
- require 'active_support/core_ext/module/remove_method'
3
- require 'active_support/core_ext/array/extract_options'
4
-
5
- class Class
6
- # Declare a class-level attribute whose value is inheritable by subclasses.
7
- # Subclasses can change their own value and it will not impact parent class.
8
- #
9
- # class Base
10
- # class_attribute :setting
11
- # end
12
- #
13
- # class Subclass < Base
14
- # end
15
- #
16
- # Base.setting = true
17
- # Subclass.setting # => true
18
- # Subclass.setting = false
19
- # Subclass.setting # => false
20
- # Base.setting # => true
21
- #
22
- # In the above case as long as Subclass does not assign a value to setting
23
- # by performing <tt>Subclass.setting = _something_ </tt>, <tt>Subclass.setting</tt>
24
- # would read value assigned to parent class. Once Subclass assigns a value then
25
- # the value assigned by Subclass would be returned.
26
- #
27
- # This matches normal Ruby method inheritance: think of writing an attribute
28
- # on a subclass as overriding the reader method. However, you need to be aware
29
- # when using +class_attribute+ with mutable structures as +Array+ or +Hash+.
30
- # In such cases, you don't want to do changes in places but use setters:
31
- #
32
- # Base.setting = []
33
- # Base.setting # => []
34
- # Subclass.setting # => []
35
- #
36
- # # Appending in child changes both parent and child because it is the same object:
37
- # Subclass.setting << :foo
38
- # Base.setting # => [:foo]
39
- # Subclass.setting # => [:foo]
40
- #
41
- # # Use setters to not propagate changes:
42
- # Base.setting = []
43
- # Subclass.setting += [:foo]
44
- # Base.setting # => []
45
- # Subclass.setting # => [:foo]
46
- #
47
- # For convenience, an instance predicate method is defined as well.
48
- # To skip it, pass <tt>instance_predicate: false</tt>.
49
- #
50
- # Subclass.setting? # => false
51
- #
52
- # Instances may overwrite the class value in the same way:
53
- #
54
- # Base.setting = true
55
- # object = Base.new
56
- # object.setting # => true
57
- # object.setting = false
58
- # object.setting # => false
59
- # Base.setting # => true
60
- #
61
- # To opt out of the instance reader method, pass <tt>instance_reader: false</tt>.
62
- #
63
- # object.setting # => NoMethodError
64
- # object.setting? # => NoMethodError
65
- #
66
- # To opt out of the instance writer method, pass <tt>instance_writer: false</tt>.
67
- #
68
- # object.setting = false # => NoMethodError
69
- #
70
- # To opt out of both instance methods, pass <tt>instance_accessor: false</tt>.
71
- def class_attribute(*attrs)
72
- options = attrs.extract_options!
73
- instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
74
- instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
75
- instance_predicate = options.fetch(:instance_predicate, true)
76
-
77
- attrs.each do |name|
78
- define_singleton_method(name) { nil }
79
- define_singleton_method("#{name}?") { !!public_send(name) } if instance_predicate
80
-
81
- ivar = "@#{name}"
82
-
83
- define_singleton_method("#{name}=") do |val|
84
- singleton_class.class_eval do
85
- remove_possible_method(name)
86
- define_method(name) { val }
87
- end
88
-
89
- if singleton_class?
90
- class_eval do
91
- remove_possible_method(name)
92
- define_method(name) do
93
- if instance_variable_defined? ivar
94
- instance_variable_get ivar
95
- else
96
- singleton_class.send name
97
- end
98
- end
99
- end
100
- end
101
- val
102
- end
103
-
104
- if instance_reader
105
- remove_possible_method name
106
- define_method(name) do
107
- if instance_variable_defined?(ivar)
108
- instance_variable_get ivar
109
- else
110
- self.class.public_send name
111
- end
112
- end
113
- define_method("#{name}?") { !!public_send(name) } if instance_predicate
114
- end
115
-
116
- attr_writer name if instance_writer
117
- end
118
- end
119
-
120
- private
121
-
122
- unless respond_to?(:singleton_class?)
123
- def singleton_class?
124
- ancestors.first != self
125
- end
126
- end
127
- end
@@ -1,13 +0,0 @@
1
- module Kernel
2
- # Returns the object's singleton class.
3
- def singleton_class
4
- class << self
5
- self
6
- end
7
- end unless respond_to?(:singleton_class) # exists in 1.9.2
8
-
9
- # class_eval on an object acts like singleton_class.class_eval.
10
- def class_eval(*args, &block)
11
- singleton_class.class_eval(*args, &block)
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- class Module
2
- def remove_possible_method(method)
3
- remove_method(method)
4
- rescue NameError
5
- end
6
-
7
- def redefine_method(method, &block)
8
- remove_possible_method(method)
9
- define_method(method, &block)
10
- end
11
- end