Skip to content

Instantly share code, notes, and snippets.

View vasilakisfil's full-sized avatar

Filippos Vasilakis vasilakisfil

View GitHub Profile
// {{ radio-button name='dish' value='spam' groupValue=selectedDish selectedAction='testAction' }} Spam
// {{ radio-button name='dish' value='eggs' groupValue=selectedDish }} Eggs
//
/*
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'input',
type: 'radio',
attributeBindings: [ 'checked', 'name', 'type', 'value' ],
@vasilakisfil
vasilakisfil / example.rb
Last active August 29, 2015 14:07
namespaced mixins
#Mixins as I sometimes want them. Proper Composition.
#It probably requires different approach on how we write mixins atm.
#@vasilakisfil
module NamespacedMixin
module ClassMethods
def namespace(name, as:)
namespace = as
namespaced_class = name.split('::').inject(Object) {|o,c| o.const_get c}
@vasilakisfil
vasilakisfil / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@vasilakisfil
vasilakisfil / put jsonapi
Created November 26, 2014 17:21
PUT relationship in JSONAPI
PUT /articles/1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"articles": {
"title": "Rails is a Melting Pot",
"links": {
"author": "1"
}
@vasilakisfil
vasilakisfil / example-ApplicationRoute.js
Last active September 22, 2016 20:18
How to show API errors in Ember
import Ember from 'ember';
import Notify from 'ember-notify';
export default Ember.Route.extend(ApplicationRouteMixin, {
actions: {
error: function (errorObject) {
if (errorObject) {
if (errorObject.status === 401) {
return this.transitionTo('login');
@vasilakisfil
vasilakisfil / console.rb
Last active August 29, 2015 14:13
Ruby hashes inconsistency
# copy and store in another variable:
[16] pry(main)> hash1 = {a: 'asdasd', b: 'asdasd'}
=> {:a=>"asdasd", :b=>"asdasd"}
[17] pry(main)> hash2 = hash1
=> {:a=>"asdasd", :b=>"asdasd"}
[18] pry(main)> hash2.delete(:a)
=> "asdasd"
[19] pry(main)> hash2
=> {:b=>"asdasd"}
[20] pry(main)> hash1
@vasilakisfil
vasilakisfil / rspec-api.rb
Last active August 29, 2015 14:14
rspec API helpers
class ObjectHash
attr_accessor :hash
def initialize(hash)
@hash = HashWithIndifferentAccess.new(hash)
end
def method_missing(name)
return hash[name] if hash.key? name
@vasilakisfil
vasilakisfil / rspec_api_helper.rb
Last active August 29, 2015 14:16
Rspec API Helper
#rspec/support/rspec_api_helper.rb
module RspecApiHelper
module ExampleMethods
def objectize_resources(json, root: root)
array = []
array_hash = HashWithIndifferentAccess.new(MultiJson.load(json))
if root
array_hash = array_hash[root]
end

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views

Rails mailer structure

Your application is growing, and you are starting to have a complex mailing system: notification emails, retention emails, misc user emails, admin emails, etc...

It's time to clean up your mailers !

Existing mailer

You may already have a single mailer, responsible of every emails, like this one: