Skip to content

Instantly share code, notes, and snippets.

View panSarin's full-sized avatar

Adam Piotrowski panSarin

View GitHub Profile
@panSarin
panSarin / gist:1627691
Created January 17, 2012 17:31
admin login helper
def login_admin(admin)
visit admin_page
fill :email => admin.email
fill :password => admin.password
click_button "Login"
end
@panSarin
panSarin / gist:1627695
Created January 17, 2012 17:31
spec_helper
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/*.rb")].each {|f| require f}
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with(:truncation)
RSpec.configure do |config|
@panSarin
panSarin / euro2012 antyspam
Created June 12, 2012 19:51
userscript for euro2012 spam in facebook
// ==UserScript==
// @name Euro2012 antyspam
// @author pan_sarin
// @description Script for replacing euro2012 facebook content into not so annoying content
// @version 0.0.3
// @include http://www.facebook.com/*
// @include https://www.facebook.com/*
// @todo user definied content ( links / images ) or more random dummy content from some rss
// ==/UserScript==
@panSarin
panSarin / gist:3131205
Created July 17, 2012 18:41
Question about simple_form wrapper
config.wrappers :my_default , :class => :input,
:hint_class => :field_with_hint, :error_class => :field_with_errors,
:label_class => "control-inline-label" do |b|
@panSarin
panSarin / gist:3145598
Created July 19, 2012 17:47
User with nested attributes , error on password problem
= simple_form_for [:admin, @user], remote: true, html: { novalidate: 'true'} do |f|
.tab-content
#basic.tab-pane.active
= f.input :login
= f.simple_fields_for :password_attributes do |pass|
= pass.input :password, label: 'Hasło'
= pass.input :password_confirmation, label: "Potwierdzenie hasła"
= pass.input :user_id, as: :hidden, input_html: {value: @user.id }, wrapper: :default
#personal.tab-pane
= f.simple_fields_for (@user.persisted? ? :personal : :personal_attributes), @user.personal do |p|
@panSarin
panSarin / gist:3229545
Created August 1, 2012 18:29
users to fcbk
def to_fcbk
@users = User.where("active = true and (first_name like '%#{params[:q]}%' OR last_name like '%#{params[:q]}%')")
@users = @users.map { |r| {value: r.id, key: "#{r.first_name} #{r.last_name} "} }
render json: @users
end
class Ability
include CanCan::Ability
def initialize(user)
if user.role?('admin')
can :manage, :all
end
if user.role?('user_manager')
can :manage, User
$ ->
$(window).on 'mercury:ready', ->
document_container = $('.document_container')
Mercury.saveUrl = document_container.data('save-url')
Mercury.saveMethod = document_container.data('save-method')
console.debug Mercury.saveMethod
require 'spec_helper'
require_relative 'controller_helper'
describe DocumentsController do
actions = rest_actions.reject{|a| a[:action] == :update}
actions << {method: :post, action: :mercury_save, params: {}}
actions << {method: :get, action: :upload, params: {}}
actions.each do |action|
{ admin: true, user: false, documents_manager: true}.each do |role, result|
it "#{role} should #{result ? '' : 'not'} have access to #{action[:method]} ##{action[:action]}" do
Document.stub(:find).and_return(Document.new) if action[:params].include?(:id)
def sign_in(role)
user = create :user, role
controller.stub!(:current_user).and_return(user)
end
def check_privilages(action, role, result)
sign_in(role)
send(action[:method], action[:action], action[:params])
if result
response.should_not redirect_to(controller: :home, action: :access_denied)