By: @BTroncone
Also check out my lesson @ngrx/store in 10 minutes on egghead.io!
Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!
Table of Contents
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })} | |
RSpec::Matchers.define :accept_nested_attributes_for do |association| | |
match do |model| | |
@model = model | |
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym) | |
if @nested_att_present && @reject | |
model.send("#{association}_attributes=".to_sym,[@reject]) | |
@reject_success = model.send("#{association}").empty? | |
end | |
model.send("#{association}").clear |
#Session controller provides a token | |
#/controllers/api/sessions_controller.rb | |
class Api::SessionsController < Devise::SessionsController | |
before_filter :authenticate_user!, :except => [:create] | |
before_filter :ensure_params_exist, :except => [:destroy] | |
respond_to :json | |
def create | |
resource = User.find_for_database_authentication(:email => params[:user_login][:email]) | |
return invalid_login_attempt unless resource |
# This is a skeleton for testing models including examples of validations, callbacks, | |
# scopes, instance & class methods, associations, and more. | |
# Pick and choose what you want, as all models don't NEED to be tested at this depth. | |
# | |
# I'm always eager to hear new tips & suggestions as I'm still new to testing, | |
# so if you have any, please share! | |
# | |
# @kyletcarlson | |
# | |
# This skeleton also assumes you're using the following gems: |
# Note (November 2016): | |
# This config is rather outdated and left here for historical reasons, please refer to prerender.io for the latest setup information | |
# Serving static html to Googlebot is now considered bad practice as you should be using the escaped fragment crawling protocol | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name yourserver.com; | |
root /path/to/your/htdocs; |
## token_authentication | |
# at the head of of controllers which will need token authentication instead of password/session authentication: | |
skip_before_action :authenticate_tenant! | |
before_action :authenticate_by_token! | |
# then in application_controller.rb: | |
def authenticate_by_token! |
require 'rails_helper' | |
RSpec.describe TodosController, :type => :controller do | |
describe "GET #index" do | |
#describe "POST #create" do | |
#describe "GET #show" do | |
#describe "PATCH #update" do (or PUT #update) | |
#describe "DELETE #destroy" do | |
#describe "GET #new" do |
import {Directive, forwardRef, Provider} from "angular2/core"; | |
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from "angular2/common"; | |
import {CONST_EXPR} from "angular2/src/facade/lang"; | |
const FILE_VALUE_ACCESSOR = CONST_EXPR( | |
new Provider(NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => FileControlValueAccessor), multi: true}) | |
); | |
/** | |
* The accessor for listening to changes that is used by the |
By: @BTroncone
Also check out my lesson @ngrx/store in 10 minutes on egghead.io!
Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!
Table of Contents
A complete example is available at https://github.com/keathmilligan/angular2-cli-auth0-example
The provided auth0 tutorial uses SystemJS, these notes outline how to integrate into an angular-cli or straight webpack project.
Create project as usual with "ng create".
Install auth0 packages & bootstrap:
// Import the core angular services. | |
import { Component } from "@angular/core"; | |
// ----------------------------------------------------------------------------------- // | |
// ----------------------------------------------------------------------------------- // | |
interface Contact { | |
id: number; | |
name: string; | |
avatarUrl: string; |