Skip to content

Instantly share code, notes, and snippets.

View marcoslebron's full-sized avatar
🖐️

Marcos Lebron marcoslebron

🖐️
View GitHub Profile
@marcoslebron
marcoslebron / open_link.js
Created July 12, 2017 18:48
opening link from select option
[1] Time.now + 10.days
[2] 10.days.from_now
[3] -10.days.ago
[4] DateTime.now.days_ago(-10)
[5] Date.today + 10
@marcoslebron
marcoslebron / truncate.slim
Created May 19, 2017 19:08
Truncate text
#hellow
hellow
#hellow
width: 10px
white-space: nowrap
overflow: hidden
text-overflow: ellipsis
@marcoslebron
marcoslebron / gist:8bdff6fbeffbb8e3f689fb15b250c0ac
Created May 18, 2017 14:18 — forked from stevenringo/gist:1077311
Has Many through factory with fabricator
class Country < ActiveRecord::Base
has_many :registrations
has_many :members
has_many :distribution_groups, :through => :members
end
class DistributionGroup < ActiveRecord::Base
has_many :members
has_many :countries, :through => :members
end
@marcoslebron
marcoslebron / capybara_form_submit.rb
Last active May 7, 2020 11:30
I was trying to submit a form without button using just Capybara and Rspec
class Capybara::Session
def submit(element)
Capybara::RackTest::Form.new(driver, element.native).submit({})
end
end
#in the test
fill_in 'Search', with: 'dice'
form = find '#search-form' # find the form
@companies = Company.includes(:company_users).search(params[:q]).page(params[:page]).per(params[:per_page]||6)
def outstanding_totals
Invoice.with_state(:sent).to_a.sum(&:total_cents)
end
def drafted_totals
Invoice.with_state(:drafted).to_a.sum(&:total_cents)
end
def paid_totals
Invoice.with_state(:paid).to_a.sum(&:total_cents)