This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ObjectHash | |
attr_accessor :hash | |
def initialize(hash) | |
@hash = HashWithIndifferentAccess.new(hash) | |
end | |
def method_missing(name) | |
return hash[name] if hash.key? name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT /articles/1 | |
Content-Type: application/vnd.api+json | |
Accept: application/vnd.api+json | |
{ | |
"articles": { | |
"title": "Rails is a Melting Pot", | |
"links": { | |
"author": "1" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
describe Api::V1::UsersController, type: :api do | |
context :index do | |
before do | |
5.times{ FactoryGirl.create(:user) } | |
5.times{ FactoryGirl.create(:admin) } | |
FactoryGirl.create(:super_admin) | |
sign_in(User.regular.last) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AuthenticationHelper | |
def sign_in(user) | |
header('Authorization', "Token token=\"#{user.authentication_token}\", user_email=\"#{user.email}\"") | |
end | |
def create_and_sign_in_user | |
user = FactoryGirl.create(:user) | |
sign_in(user) | |
return user | |
end |