Yeomanのgenerate-angularで作成したプロジェクト(CoffeeScript)にKarma-Coverageを導入する

ココを見ましょう。

ありがとうございます。

やった内容

// package.json

 "karma-coverage": "git+https://github.com/mokemokechicken/karma-coverage.git#master",
% npm l
#karma.conf.js
       'karma-phantomjs-launcher'
       'karma-jasmine'
       'karma-coffee-preprocessor'
+      'karma-coverage'
     ]

# ............................................

-    preprocessors: '**/*.coffee': ['coffee']
+    preprocessors:
+      'app/scripts/*.coffee': 'coffee'
+      'app/scripts/*/**/*.coffee': 'coverage'
+      'test/**/*.coffee': 'coffee'
 
     # Uncomment the following lines if you are using grunt's server to run the tests
     # proxies: '/': 'http://localhost:9000/'
     # URL root prevent conflicts with the site root
     # urlRoot: '_karma_'
+
+    reporters: ['progress','coverage']

OK.そのうち解決されることを願いつつ。

参考

Railsのwrap_parametersは何をしてくれるのか?

Action Controller Overview — Ruby on Rails Guides
↑ここに書いてある。

config/initializers/wrap_parameters.rbはRails4.1だとデフォルトで多分こうなっている。↓

 Be sure to restart your server when you modify this file.

# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.

# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
  wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
end

# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
#  self.include_root_in_json = true
# end

この設定のままの場合は要するに'application/json'でJSONRailsへ送った時にルート要素を省いて送れる。

//↓これが
{ "user": { "name": "katahirado", "address": "Kakyouin" } }
//↓こう送れる
{ "name": "katahirado", "address": "Kakyouin" }

↓Controllerへ送るとパラメータはこうなる

{ name: "katahirado", address: "Kakyouin", user: { name: "katahirado", address: "Kakyouin" }}

何が嬉しいのかというと、例えばAngularJSとかからJSONを送るときに$resourceで処理しやすい、でもって、Rails側では通常と変わらずUser.new(params[:user])と出来る*1、とかそういう感じで。

ちなみにController名にしたがってラップされるので、そこは注意が必要。
例えばDeviseのRegistrationsControllerの場合は、registration: {...}とラップされてる。

DeviseはJSON考慮に入れてないので、APIとかの用途の場合はSorceryとか、自前とか、oAuthの仕組みに乗るとかしたほうが良さ気。

*1:説明の為にStrongParametersを省いてます