lanes 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/Gemfile +2 -3
  4. data/client/lanes/boot.jsx +1 -1
  5. data/client/lanes/index.js +0 -11
  6. data/client/lanes/jest/matchers.js +14 -0
  7. data/{lib/js/jest/mocks.js → client/lanes/jest/mocks/fetch.js} +1 -1
  8. data/client/lanes/models/base.js +0 -32
  9. data/client/lanes/screens/definition.js +7 -8
  10. data/client/lanes/screens/index.js +24 -240
  11. data/client/lanes/workspace/menu.jsx +3 -34
  12. data/client/lanes/workspace/screen.jsx +3 -3
  13. data/config/routes.rb +2 -0
  14. data/config/screens.rb +2 -2
  15. data/lanes.gemspec +10 -7
  16. data/lib/lanes/access/authentication_provider.rb +4 -4
  17. data/lib/lanes/api.rb +1 -0
  18. data/lib/lanes/api/default_routes.rb +1 -1
  19. data/lib/lanes/api/handlers/screens.rb +26 -0
  20. data/lib/lanes/api/helper_methods.rb +5 -4
  21. data/lib/lanes/cli.rb +7 -0
  22. data/lib/lanes/command/app.rb +4 -6
  23. data/lib/lanes/command/client_config.rb +59 -0
  24. data/lib/lanes/command/generate_model.rb +4 -4
  25. data/lib/lanes/command/jest.rb +14 -29
  26. data/lib/lanes/command/model_attribute.rb +6 -1
  27. data/lib/lanes/command/named_command.rb +1 -0
  28. data/lib/lanes/command/puma.rb +56 -0
  29. data/lib/lanes/command/server.rb +21 -18
  30. data/lib/lanes/command/webpack.rb +54 -0
  31. data/lib/lanes/extension.rb +0 -7
  32. data/lib/lanes/guard_tasks.rb +21 -20
  33. data/lib/lanes/rake_tasks.rb +13 -0
  34. data/lib/lanes/reloadable_sinatra.rb +24 -0
  35. data/lib/lanes/screen.rb +15 -6
  36. data/lib/lanes/spec_helper.rb +70 -136
  37. data/lib/lanes/version.rb +1 -1
  38. data/package.json +1 -1
  39. data/spec/server/api/controller_base_spec.rb +61 -53
  40. data/spec/server/spec_helper.rb +37 -45
  41. data/templates/client/models/model.js +17 -0
  42. data/templates/config/database.yml +2 -1
  43. data/templates/config/jest.config.json +14 -0
  44. data/templates/config/jest/babel-transform.js +47 -0
  45. data/templates/config/routes.rb +3 -2
  46. data/templates/config/webpack.config.js +1 -1
  47. data/templates/js/jest.config.json +2 -10
  48. data/templates/spec/client/models/model.spec.js +10 -0
  49. data/templates/spec/client/setup.js +9 -0
  50. data/templates/spec/server/spec_helper.rb +3 -11
  51. metadata +40 -41
  52. data/lib/js/jest.config.json +0 -14
  53. data/lib/js/jest/fileMock.js +0 -1
  54. data/lib/js/jest/setup.js +0 -26
  55. data/lib/js/jest/stubs/screen-definitions.js +0 -0
  56. data/lib/js/jest/styleMock.js +0 -1
  57. data/lib/js/webpack.config.js +0 -93
  58. data/lib/lanes/hot_reload_plugin.rb +0 -47
  59. data/lib/lanes/webpack.rb +0 -73
  60. data/spec/server/api/coffeescript_processor_spec.rb +0 -116
  61. data/templates/client/models/Model.coffee +0 -17
  62. data/templates/spec/client/models/ModelSpec.coffee +0 -5
@@ -0,0 +1,54 @@
1
+ require 'forwardable'
2
+ require 'fileutils'
3
+ require 'pathname'
4
+
5
+ module Lanes
6
+
7
+ module Command
8
+
9
+ class Webpack < Thor::Group
10
+ include Thor::Actions
11
+
12
+ attr_reader :process
13
+
14
+ attr_accessor :config
15
+
16
+ attr_reader :wpd_config
17
+
18
+ class_option :wait, :type => :boolean, default: true,
19
+ desc: "Whether to keep running and wait for exit"
20
+
21
+ def make_config
22
+ return if @config
23
+ @config = ClientConfig.new
24
+ config.invoke_all
25
+ end
26
+
27
+ def configure
28
+ @wpd_config = WebpackDriver::Configuration.new(
29
+ config.extension_path.join('config', 'webpack.config.js'),
30
+ cmd_line_flags: ['--hot', '--inline'],
31
+ logger: Lanes.logger,
32
+ directory: config.controlling_extension.root_path
33
+ )
34
+
35
+ wpd_config.environment.merge!(
36
+ EXTENSION_ID: config.controlling_extension.identifier,
37
+ LANES_MODULES: config.module_paths.join(':'),
38
+ ENTRY: 'show-maker/index.js',
39
+ GENERATED_CONFIG_DIR: config.directory.to_s
40
+ )
41
+
42
+ self
43
+ end
44
+
45
+ def startup
46
+ @process = ::WebpackDriver::DevServer.new(wpd_config)
47
+ @process.start
48
+ @process.wait if options[:wait]
49
+ end
50
+
51
+ end
52
+ end
53
+
54
+ end
@@ -17,13 +17,6 @@ module Lanes
17
17
  end
18
18
  end
19
19
 
20
- def asset_paths(controller, additional)
21
- map { |ext| ext.root_path.join('client').to_s }.reverse + [
22
- controller.root_path.join('node_modules').to_s,
23
- additional
24
- ]
25
- end
26
-
27
20
  # lock the current controlling extension so that it can't
28
21
  # be changed by other extensions that are loaded later
29
22
  def lock_controlling!
@@ -1,19 +1,15 @@
1
- require_relative "../lanes"
2
- # require 'guard/jasmine'
3
- require "guard/jest"
4
- require 'guard/minitest'
5
- require "net/http"
6
- require "uri"
7
- # require_relative "lanes_guard_plugin"
8
-
9
- # require_relative "hot_reload_plugin"
1
+ require_relative '../lanes'
10
2
  require_relative 'command/jest'
3
+ require_relative 'reloadable_sinatra.rb'
4
+ require 'guard/jest'
5
+ require 'guard/rspec'
11
6
 
12
7
  module Lanes
13
8
  module GuardTasks
9
+ mattr_accessor :client_config
14
10
 
15
11
  class CustomMatchers
16
- attr_reader :client_matches, :server_matches#, :hot_reload
12
+ attr_reader :client_matches, :server_matches
17
13
 
18
14
  def client(&block)
19
15
  @client_matches = block
@@ -29,27 +25,32 @@ module Lanes
29
25
  matchers = CustomMatchers.new
30
26
  yield matchers
31
27
 
28
+ config = client_config || ::Lanes::Command::Jest.new.configure.config
29
+
32
30
  jest_options = options.merge(
33
31
  logger: Lanes.logger,
34
32
  silent: false,
35
33
  jest_cmd: './node_modules/.bin/jest',
36
- config_file: ::Lanes::Command::Jest.new.configure.config_file
34
+ config_file: config.directory.join('jest.config.json')
37
35
  )
38
-
39
36
  dsl.guard :jest, jest_options
40
37
 
41
-
42
- minitest_options = {
43
- all_on_start: false, test_folders: 'spec/server'
38
+ rspec_options = {
39
+ all_on_start: false,
40
+ cmd: 'bundle exec rspec'
44
41
  }
45
- dsl.guard :minitest, minitest_options do
46
- dsl.watch(%r{^spec/server/spec_helper\.rb}) { 'test' }
42
+ dsl.guard :rspec, rspec_options do
43
+ # dsl.watch(%r{^spec/server/spec_helper\.rb}) { 'spec' }
47
44
  dsl.watch(%r{^spec/server/.*_spec\.rb})
48
- dsl.watch(%r{^spec/fixtures/#{app_name}/(.+)s\.yml}) { |m| "spec/server/#{m[1]}_spec.rb" }
49
- dsl.watch(%r{^lib/#{app_name}/(.+)\.rb}) { |m| "spec/server/#{m[1]}_spec.rb" }
50
- matchers.server_matches.call if matchers.server_matches
45
+ # dsl.watch(%r{^spec/fixtures/#{app_name}/(.+)s\.yml}) { |m| "spec/server/#{m[1]}_spec.rb" }
46
+ # dsl.watch(%r{^lib/#{app_name}/(.+)\.rb}) { |m| "spec/server/#{m[1]}_spec.rb" }
47
+ # matchers.server_matches.call if matchers.server_matches
51
48
  end
52
49
 
50
+ dsl.guard :reloadable_sinatra do
51
+ dsl.watch(%r{^lib/.*\.rb})
52
+
53
+ end
53
54
  end
54
55
 
55
56
  end
@@ -1,12 +1,21 @@
1
1
  require 'puma/control_cli'
2
2
  require 'resque/tasks'
3
3
  require_relative '../lanes'
4
+ require_relative 'command/jest'
4
5
 
5
6
  desc "Run the puma server in development mode"
6
7
  task :dev do
7
8
  Puma::ControlCLI.new(['start']).run
8
9
  end
9
10
 
11
+ begin
12
+ require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask.new(:spec) do |t|
14
+ t.pattern = Dir.glob('spec/server/**/*_spec.rb')
15
+ end
16
+ rescue LoadError
17
+ end
18
+
10
19
  desc "Open an irb session configured with the Lanes environment"
11
20
  task :console do
12
21
  require 'irb'
@@ -53,3 +62,7 @@ namespace :assets do
53
62
  Lanes::API::SprocketsExtension.compile!
54
63
  end
55
64
  end
65
+
66
+ task :test => [:spec] do
67
+ ::Lanes::Command::Jest.new.configure.single_run
68
+ end
@@ -0,0 +1,24 @@
1
+ require 'guard/compat/plugin'
2
+ require_relative 'command/puma'
3
+
4
+ module ::Guard
5
+
6
+ class ReloadableSinatra < ::Guard::Plugin
7
+ def start
8
+ puts "RELOAD"
9
+ @puma = ::Lanes::Command::Puma.new
10
+ @puma.start
11
+ end
12
+
13
+ def run_on_modifications(paths)
14
+ @puma.stop
15
+ @puma.start
16
+ end
17
+
18
+ def stop
19
+ @puma.stop
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -15,14 +15,17 @@ module Lanes
15
15
  end
16
16
 
17
17
  def define(id)
18
- definition = ( DEFINITIONS[id] ||= Definition.new(id, @extension_id) )
18
+ definition = (DEFINITIONS[id] ||= Definition.new(id, @extension_id))
19
19
  yield definition
20
20
  end
21
21
  end
22
22
 
23
23
  class << self
24
+
25
+ include Enumerable
26
+
24
27
  def [](config)
25
- if DEFINITIONS.has_key?(config)
28
+ if DEFINITIONS.key?(config)
26
29
  DEFINITIONS[config]
27
30
  else
28
31
  nil
@@ -49,12 +52,9 @@ module Lanes
49
52
  end
50
53
 
51
54
  def config_file
52
- Lanes::Extensions.controlling.root_path.join("config","screens.rb")
55
+ Lanes::Extensions.controlling.root_path.join("config", "screens.rb")
53
56
  end
54
57
 
55
- def uncache_file_on_update(asset)
56
- asset.depend_on(config_file) if config_file.exist?
57
- end
58
58
  end
59
59
 
60
60
 
@@ -96,6 +96,10 @@ module Lanes
96
96
  @extension = extension_id.underscore.camelize
97
97
  end
98
98
 
99
+ def group
100
+ GROUPS[@group_id]
101
+ end
102
+
99
103
  def has_file_matching?(pattern)
100
104
  Pathname.glob(root_path.join(pattern)).any?
101
105
  end
@@ -106,6 +110,11 @@ module Lanes
106
110
  ext.root_path.join('client', url_prefix, identifier)
107
111
  end
108
112
 
113
+ def model
114
+ ext = Lanes::Extensions.for_identifier(@extension_id)
115
+ (@extension_id.camelize + '::' + @model_class).constantize
116
+ end
117
+
109
118
  def as_json
110
119
  {
111
120
  id: identifier,
@@ -1,154 +1,88 @@
1
- require 'minitest/autorun'
2
1
  require 'rack/test'
3
2
  require 'lanes'
4
3
  require 'lanes/api'
5
4
  require 'hashie/mash'
6
5
  require 'active_record'
7
6
  require 'active_record/fixtures'
8
- require 'minitest/around/unit'
9
- require 'minitest/around/spec'
10
- require 'minitest/spec'
11
- require 'minitest/autorun'
12
- require 'mocha/mini_test'
13
7
 
14
8
  LANES_ENV = "test"
15
- I18n.enforce_available_locales = true
16
- Lanes::DB.establish_connection
17
- Lanes.logger = Logger.new(
18
- File.open('log/test.log', File::WRONLY | File::APPEND | File::CREAT )
19
- )
20
- ActiveRecord::Base.logger = Lanes.logger
21
- ActiveSupport::Dependencies.mechanism = :require
22
- ActiveSupport.test_order = :random
23
9
 
24
- module Lanes
10
+ RSpec.configure do |config|
25
11
 
26
- class DummyUser
27
- def can_read?(*args)
28
- true
29
- end
30
- def can_write?(*args)
31
- true
32
- end
33
- def can_delete?(*args)
34
- true
35
- end
36
- end
37
-
38
- class TestCase < ActiveSupport::TestCase
39
- include Lanes
40
-
41
- include ActiveRecord::TestFixtures
42
- self.fixture_path = Lanes::Extensions.controlling.root_path.join('spec','fixtures')
43
12
 
44
- self.use_transactional_tests = true
45
- fixtures :all
13
+ # Use color in STDOUT
14
+ config.color = true
46
15
 
47
- def admin
48
- lanes_users(:admin)
49
- end
50
-
51
- extend MiniTest::Spec::DSL
52
- register_spec_type self do |desc|
53
- desc < Lanes::Model if desc.is_a? Class
54
- end
55
16
 
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
56
29
  end
57
30
 
58
- class ApiTestCase < TestCase
59
- include Rack::Test::Methods
60
-
61
- teardown do
62
- @current_user = nil
63
- end
64
-
65
- def app
66
- Lanes::API::Root.new
67
- end
68
-
69
- def json_body
70
- Hashie::Mash.new Oj.load( last_response.body )
71
- end
72
-
73
- def json_data
74
- json_body['data']
75
- end
76
-
77
- [ :delete, :get ].each do |name|
78
- define_method(name) do |uri, params = {}, env = {}, &block|
79
- session = env['rack.session'] ||= {}
80
- session[:user_id] = @current_user.id if @current_user
81
- params.stringify_keys!
82
- super(uri, params, env, &block)
83
- end
84
- end
85
-
86
- [ :put, :post, :patch].each do |name|
87
- define_method(name) do |uri, params = {}, env = {}, &block|
88
- session = env['rack.session'] ||= {}
89
- session[:user_id] = @current_user.id if @current_user
90
- params = Oj.dump(params, mode: :compat) if params.is_a?(Hash)
91
- super(uri, params, env, &block)
92
- end
93
- end
94
-
95
- def login!(user=admin)
96
- @current_user = user
97
- end
98
-
99
- def assert_ok
100
- assert last_response.ok?, "Request failed with #{last_response.status}"
101
- end
102
- def refute_ok
103
- refute last_response.ok?, "Request succeeded with status #{last_response.status}, expected non-2XX"
104
- end
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
105
38
  end
106
- end
107
-
108
- module MiniTest
109
- module Assertions
110
-
111
- def assert_logs_matching( regex, failure_message=nil, &block )
112
- old_logger = Lanes.logger
113
- begin
114
- output = ""
115
- Lanes.logger=Logger.new( StringIO.new(output) )
116
- yield
117
- assert_match( regex, output, failure_message )
118
- ensure
119
- Lanes.logger=old_logger
120
- end
121
- end
122
-
123
-
124
- def assert_saves( model )
125
- assert model.save, "#{model.class} failed to save: #{model.errors.full_messages.join(',')}"
126
- end
127
-
128
- def refute_saves( model, *errors )
129
- refute model.save, "#{model.class} saved successfully when it should not have"
130
- errors.each do |error|
131
- if model.errors[error.to_sym].empty?
132
- raise MiniTest::Assertion, "expected #{model.class} to have an error on #{error}"
133
- end
134
- end
135
39
 
136
- end
137
-
138
- def assert_event_fires( klass, event, &block )
139
- @event_results = []
140
- klass.observe(event) do | *args |
141
- @event_results = args
142
- end
143
- yield
144
- raise MiniTest::Assertion, "Event #{event} was not fired" if @event_results.empty?
145
- end
146
-
147
- def last_event_results
148
- @event_results
149
- end
150
- end
40
+ # The settings below are suggested to provide a good initial experience
41
+ # with RSpec, but feel free to customize to your heart's content.
42
+ =begin
43
+ # These two settings work together to allow you to limit a spec run
44
+ # to individual examples or groups you care about by tagging them with
45
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
46
+ # get run.
47
+ config.filter_run :focus
48
+ config.run_all_when_everything_filtered = true
49
+
50
+ # Limits the available syntax to the non-monkey patched syntax that is
51
+ # recommended. For more details, see:
52
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
53
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
54
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
55
+ config.disable_monkey_patching!
56
+
57
+ # This setting enables warnings. It's recommended, but in some cases may
58
+ # be too noisy due to issues in dependencies.
59
+ config.warnings = true
60
+
61
+ # Many RSpec users commonly either run the entire suite or an individual
62
+ # file, and it's useful to allow more verbose output when running an
63
+ # individual spec file.
64
+ if config.files_to_run.one?
65
+ # Use the documentation formatter for detailed output,
66
+ # unless a formatter has already been configured
67
+ # (e.g. via a command-line flag).
68
+ config.default_formatter = 'doc'
69
+ end
70
+
71
+ # Print the 10 slowest examples and example groups at the
72
+ # end of the spec run, to help surface which specs are running
73
+ # particularly slow.
74
+ config.profile_examples = 10
75
+
76
+ # Run specs in random order to surface order dependencies. If you find an
77
+ # order dependency and want to debug it, you can fix the order by providing
78
+ # the seed, which is printed after each run.
79
+ # --seed 1234
80
+ config.order = :random
81
+
82
+ # Seed global randomization in this process using the `--seed` CLI option.
83
+ # Setting this allows you to use `--seed` to deterministically reproduce
84
+ # test failures related to randomization by passing the same `--seed` value
85
+ # as the one that triggered the failure.
86
+ Kernel.srand config.seed
87
+ =end
151
88
  end
152
-
153
-
154
- require_relative 'access/test_fixture_extensions'