Handlebars Asset not Compiling with ember-rails after Upgrade to Rails 4 - ember.js

I have a Rails app with Ember on the front-end. Today, I upgraded to Rails 4 and the only issue I cannot resolve is that my Handlebars templates are not being compiled or included as an asset (in development mode). I'm not getting any error messages.
I generated a brand new Rails 4 test app and installed Ember and it serves the Handlebars files just fine. All gems in the test app are present in my app. I tried running rake rails:upgrade, and that had no effect. I tried modifying the ember-rails source to output log messages and the messages and execution paths were the same for the test app and my app.
I'm requiring the templates the same way I always did:
require_tree ./templates
I tried using ember-rails 0.11.1 and from Github master, with no luck.
Related gem versions:
* ember-data-source (0.0.5)
* ember-rails (0.11.1 4dc902b)
* ember-source (1.0.0.rc2.0)
* sprockets (2.9.0)
* sprockets-rails (2.0.0.rc3)
* barber (0.4.1)
Templates are all in app/assets/javascripts/templates and all use the extension .handlebars. Although I tried .hbs and .js.hjs too.
From the Chrome console:
Ember.TEMPLATES
Object {}
I am able to manually compile assets from the Rails command line like this:
environment = Sprockets::Environment.new
environment.append_path 'app/assets/javascripts'
a = environment['templates/test.handlebars']
a.to_s => "..compiled template.."
And the engine is registered:
environment.engines
=> {..".handlebars"=>Ember::Handlebars::Template..}
Rails.application.config.assets.paths includes the app/assets/javascripts folder, as it should.
Any help with this would be greatly appreciated, Thanks!

I've narrowed it down to the following block in ember-rail's engine.rb file. For my app, it is sending register_engine on Sprockets, not app.assets. On the fresh Rails 4 test app, it was also doing this. However, in my app when I force the execution to use app.assets, the handlebar templates are compiled.
I believe since my app was upgraded from Rails 3, somewhere some configuration is missing to properly use Sprockets. I'll post more when I know.
initializer "ember_rails.setup", :after => :append_assets_path, :group => :all do |app|
sprockets = if ::Rails::VERSION::MAJOR == 4
Sprockets.respond_to?('register_engine') ? Sprockets : app.assets
else
app.assets
end
sprockets.register_engine '.handlebars', Ember::Handlebars::Template
sprockets.register_engine '.hbs', Ember::Handlebars::Template
sprockets.register_engine '.hjs', Ember::Handlebars::Template
end
UPDATE:
For me,changing the railties order in application.rb was enough to fix the problem. I believe some other engine was clearing the Sprockets config, so by loading the Ember::Rails engine later in the process, I was able to hack a way around that issue.
config.railties_order = [:main_app, :all, Ember::Rails::Engine]

Related

Is dusk is mandatory to write phpunit test cases?how to write phpunit test cases in laravel 5.4?

I am newbie to laravel. I am using laravel 5.4 version, we have requirement of writing phpunit test cases for our application, So I have searched for writing phpunit testcases and also read the documentation in laravel website. I read about the 'dusk' feature for doing the browser tests. So, I have a doubt that is "Is the dusk is mandatory for writing the phpunit test cases in laravel 5.4? I also tried to install the 'dusk' package into our application but it is not getting installed after I run the command "composer require laravel/dusk".
below is the error that I am getting on command prompt:
c:\xampp\htdocs\ourappname>composer require laravel/dusk
using version ^1.1 for laravel/dusk
./composer.json has been updated
Loading composer repositories with package information
Updating dependies (including require-dev)
Package operations: 2 installs, 4 updates, 9 removals
- Removing maatwebsite/excel (2.1.17)
- Removing phpoffice/phpexcel (1.8.1)
- Removing jeremeamia/superclosure (2.3.0)
- Removing symfony/polyfill-php56 (v1.3.0)
- Removing symfony/polyfill-util (v1.3.0)
- Removing guzzlehttp/guzzle (6.2.3)
- Removing guzzlehttp/psr7 (1.4.2)
- Removing psr/http-message (1.0.1)
- Removing guzzlehttp/promises (v1.3.1)
- Updating psy/psysh (v0.8.3 => v0.8.5): Loading from cache
- Updating swiftmailer/swiftmailer (v5.4.7 => v5.4.8): Loading from cache
- Updating sebastian/diff (1.4.1 => 1.4.2): Loading from cache
- Updating laravel/framework (v5.4.21 => v5.4.23): Loading from cache
- Installing facebook/webdriver (1.4.1): Loading from cache
- Installing laravel/dusk (v1.1.0): Loading from cache
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Maatwebsite\Excel\ExcelServiceProvider' not found
Script php artisan optimize handling the post-update-cmd event returned with error code 1
Installation failed, reverting ./composer.json to its original content.
c:\xampp\htdocs\ourappname>
Anyone please tell me how to fix it? and also what is the process for writing the test cases in laravel 5.4? should we use 'dusk'? or any other way to do it? Thanks.
No, Dusk is not required to do unit testing. You can just use the basic tests.
Your error is related to when you installed the Excel package on your application; the Service Provider was added to your config/app.php, but now that you've removed the package from your application ("Removing maatwebsite/excel (2.1.17)") you also need to remove the Service Provider.

Rails 4.2 Time_zone_conversion.rb Error. How do I fix this?

I am totally lost on this one. I'm using ruby 2.2.4 and upgrading an app from rails 4.1.0 to 4.2. The app was working fine. I changed my Gemfile to use:
gem 'rails', '~>4.2'
Then ran my spec tests and the app blew up with this error:
usr/local/rvm/rubies/ruby-2.2.4/bin/ruby -I/path-to-my-app/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.5.0/lib:/path-to-my-app/vendor/bundle/ruby/2.2.0/gems/rspec-support-3.5.0/lib /path-to-my-app/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.5.0/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
Coverage report generated for RSpec to /path-to-my-app/coverage. 22 / 1206 LOC (1.82%) covered.
/path-to-my-app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.7.1/lib/active_record/attribute_methods/time_zone_conversion.rb:64:in `create_time_zone_conversion_attribute?': undefined method `type' for "NUMBER(38)":String (NoMethodError)
from /path-to-my-app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.7.1/lib/active_record/attribute_methods/time_zone_conversion.rb:53:in `block (2 levels) in inherited'
When I try to load the app in a browser I get an error:
undefined method 'type' for "NUMBER(38)":String
I Google'd on this and found one post. It was here in StackOverflow: NoMethodError: Undefined method 'type' for nil:NilClass in Rails, which led me to: https://gist.github.com/alsemyonov/88826/revisions
I tried the fix posted in the github app, but I still get the same error.
A mention of 'time_zone_conversion.rb' in the error and something I read made me think this was :datetime related. I have one method in a couple of models that works on the date field "updated_at". Not sure if this is related or not.
def updated_at_formatted
self.updated_at.strftime("%m/%d/%Y")
end
I'm also using the gem 'american_date'.
Any ideas on what is causing this and how to fix it would be greatly appreciated.
Thanks,
Found it:
Oracle enhanced adapter version 1.6 just supports Rails 4.2 and does not support Rails 4.1 or lower version of Rails.
When using Ruby on Rails version 4.2 then in Gemfile include
gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
A co-worker and I stepped through the stacktrace on the error. He felt that the line:
undefined method 'type' for "NUMBER(38)":String
was somehow tied to a database issue, which for this app is Oracle. Googling on issues on the Rails 4.2 upgrade and the above oracle gem led us to the above answer.

Can't start test server on physical device

I installed calabash on a new machine, but tests that I ran on my old machine will not run.
As far as I can tell, both machines are set up the same way. They pull the project from the same repository, which includes a Gemfile with calabash-cucumber version 0.18.0. I set the same BUNDLE_ID, DEVICE_ENDPOINT, and DEVICE_TARGET values and use the same physical device.
When I try to run the tests in the console on the new machine, I get this:
$ bundle exec calabash-ios console
Running irb...
irb(main):001:0> start_test_server_in_background
ArgumentError: Could not find a device with a UDID or name matching 'com.my.apps.bundle.id'
from /Users/rjones/gambit/gemstubs/ruby/2.1.0/gems/run_loop-2.1.1/lib/run_loop/device.rb:126:in `device_with_identifier'
from /Users/rjones/gambit/gemstubs/ruby/2.1.0/gems/run_loop-2.1.1/lib/run_loop/device.rb:160:in `detect_device'
from /Users/rjones/gambit/gemstubs/ruby/2.1.0/gems/run_loop-2.1.1/lib/run_loop/core.rb:71:in `run_with_options'
from /Users/rjones/gambit/gemstubs/ruby/2.1.0/gems/run_loop-2.1.1/lib/run_loop.rb:134:in `run'
from /Users/rjones/gambit/gemstubs/ruby/2.1.0/gems/calabash-cucumber-0.18.0/lib/calabash-cucumber/launcher.rb:718:in `block in new_run_loop'
from /Users/rjones/gambit/gemstubs/ruby/2.1.0/gems/calabash-cucumber-0.18.0/lib/calabash-cucumber/launcher.rb:716:in `times'
from /Users/rjones/gambit/gemstubs/ruby/2.1.0/gems/calabash-cucumber-0.18.0/lib/calabash-cucumber/launcher.rb:716:in `new_run_loop'
from /Users/rjones/gambit/gemstubs/ruby/2.1.0/gems/calabash-cucumber-0.18.0/lib/calabash-cucumber/launcher.rb:584:in `relaunch'
from /Users/rjones/gambit/gemstubs/ruby/2.1.0/gems/calabash-cucumber-0.18.0/lib/calabash-cucumber/core.rb:943:in `start_test_server_in_background'
from (irb):1
from /Users/rjones/.rbenv/versions/2.1.5/bin/irb:11:in `<main>'
Any ideas why this isn't working?
Please update to 0.19.0.
Can you also paste the exact command you are using to start the
irb(main):001:0> start_test_server_in_background
ArgumentError: Could not find a device with a UDID or name matching
'com.my.apps.bundle.id'
It looks like you set your DEVICE_TARGET to the bundle id? If not, then you have found a bug. It is possible that 0.18.0 is not compatible with run-loop 2.1.1. Downgrade to run_loop 2.0.9 if you want to verify that this is the problem.
I experienced the same issue, when updating cucumber gem from version 1.3.19 to version 2.3.3. I also run tests on physical devices
edit: Sorry, forgot to mention, that I updated run_loop too from version 2.0.6 to 2.1.3
So the versions:
run_loop (2.1.3)
calabash-cucumber (0.18.1)
I guess these are the two that could affect this part, and cucumber was not involved
I found a solution, by setting the variable DEVICE instead of DEVICE_TARGET
For example:
BUNDLE_ID=<bundle_id> DEVICE=<dev_udid> DEVICE_ENDPOINT=<dev_ip> cucumber
Instead of
BUNDLE_ID=<bundle_id> DEVICE_TARGET=<dev_udid> DEVICE_ENDPOINT=<dev_ip> cucumber

RSpec 3, capybara 2.3.0, Guard 2.6.1, Rails 4.1.1 uninitialized constant (NameError)

I've recently had to migrate a project from rails 4.0 to rails 4.1 and in the process I've also updated RSpec to RSpec (3.0.0).
The project previously had the following in certain feature specs being tested with Capybara:
require 'spec_helper' require 'support/integration_helpers.rb'
require 'support/admin_support/admin_user_creation_helpers.rb'
include BuildDefaults
The include BuildDefaults refers to a module spec/support/build_defaults.rb and has various helper methods to ensure that the database has been populated correctly. For some reason this has now stopped working and gives the following error (and stack trace):
path_to/spec/features/admin_features/admin_login_out_spec.rb:4:in
<top (required)>': uninitialized constant BuildDefaults (NameError)
from
/Users/u_name/.rvm/gems/ruby-2.1.2#gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in
block in load_spec_files' from
/Users/u_name/.rvm/gems/ruby-2.1.2#gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in
each' from
/Users/u_name/.rvm/gems/ruby-2.1.2#gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in
load_spec_files' from
/Users/u_name/.rvm/gems/ruby-2.1.2#gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:97:in setup' from
/Users/u_name/.rvm/gems/ruby-2.1.2#gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:85:inrun' from
/Users/u_name/.rvm/gems/ruby-2.1.2#gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:70:in run' from
/Users/u_name/.rvm/gems/ruby-2.1.2#gemset_name/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:ininvoke' from
/Users/u_name/.rvm/gems/ruby-2.1.2#gemset_name/gems/rspec-core-3.0.2/exe/rspec:4:in
<top (required)>' from
/Users/u_name/Documents/rails/work/c_central_4.1.1/gemset_name/bin/rspec:7:in
' from
/Users/u_name/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in
require' from
/Users/u_name/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in
require' from -e:1:in `'
Would anybody happen to know why this has happened?
I would greatly appreciate any help on the matter.
I have looked at various other SO questions with a similar title as this one but none of them seem to be relevant.
Side note 1
It is worth noting that I have removed Spork from my test environment as it was not playing nicely for some reasons but have instead configured the project to use Spring. Though I don't think that this has anything to do with the issue, I did have to completely rebuild the test environment (running rails g rspec:install for instance) and then used Transpec to update the Rspec syntax.
Having spent some time looking around for a solution to this I eventually came across the official upgrade documentation (I know, I know).
As it says in the docs,
Default helper files created in RSpec 3.x have changed
In prior versions, only a single spec_helper.rb file was generated. This file
has been moved to rails_helper.rb. The new spec_helper.rb is the same
standard helper generated by running rspec --init.
This change was made to accomplish two general goals:
Keep the installation process in sync with regular RSpec changes
Provide an out-of-the-box way to avoid loading Rails for those specs
that do not require it
This second point got me thinking about the fact that a feature spec for capybara would need to load the application stack. As such, by loading the rails_helper.rb instead of the spec_helper.rb the spec/support/build_defaults.rb is now included in the load path.
Hope this helps somebody in the future.

Permission denied error with phantomjs

I am using Rails 4.0.2, Guard 2.2.4, guard-rspec 4.2.4, rspec-rails 2.14.0, Capybara 2.2.1 and Poltergeist 1.5.0 on Ruby 2.0.0-p353 and OSX Mavericks.
When I run bundle exec guard I got a lot of failure with this error message :
An error occurred in an after hook
Errno::EACCES: Permission denied - /usr/local/Cellar/phantomjs
occurred at /Users/gillesmath/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/open3.rb:211:in `spawn'
I checked the permission on /usr/local/Cellar/phantomjs and didn't notice anything unusual. I can run phantomjs without 'sudo'.
My spec_helper file look like this :
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", FILE)
require 'rspec/rails'
require 'rspec/autorun'
require "capybara/rspec"
require 'webmock/rspec'
require 'capybara/poltergeist'
Dir[Rails.root.join("spec/support/*/.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
WebMock.disable_net_connect!(:net_http_connect_on_start => true, :allow_localhost => true)
Capybara.javascript_driver = :poltergeist
I can't see what is wrong because the owner:group is the same for both the rails app and the /usr/local/Cellar/phantomjs dir and its content.
Thanks for your help
That error makes it look like it's trying to execute the /usr/local/Cellar/phantomjs directory instead of the executable inside it. I think Poltergeist scans your PATH for the first thing called phantomjs. Is /usr/local/Cellar in your PATH?
If so, I'd recommend taking it out, since executables should never appear in there directly.
If you can't, another option is to configure Poltergeist with an explicit path to phantomjs in your setup code: https://github.com/jonleighton/poltergeist#customization
It looks like someone has already opened a pull request with a fix to skip directories in the Cliver gem that Poltergeist uses, so hopefully that will be fixed soon!