Skip to content

Instantly share code, notes, and snippets.

View andrzejkrzywda's full-sized avatar

Andrzej Krzywda andrzejkrzywda

View GitHub Profile
def create
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
@time_entry.safe_attributes = params[:time_entry]
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
if @time_entry.save
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_create)
def create
CreateTimeEntryService.new(self).call()
end
class CreateTimeEntryService < SimpleDelegator
def initialize(parent)
super(parent)
end
def call
def create
if issue_id.present?
log_time_on_issue
else
log_time_on_project
end
end
def log_time_on_project
log_time(nil, project_id) { do_log_time_on_project }
# CUSTOM EXCEPTIONS
class CallAlreadyInProgress < StandardError
end
class Dialer
def call(number)
raise CallAlreadyInProgress.new if call_already_in_progress?
end
end
def create
begin
PublishBlogPost.new.call(post_id)
rescue BlogPostNotFound
redirect_to foo
rescue AlreadyPublished
flash[:error] = already_plublished_message
render :foo
end
end
@andrzejkrzywda
andrzejkrzywda / gist:a3306ac5779a87aff255
Created December 12, 2014 21:04
Integration test for a scaffolded Post(title, content) which goes through all the pages. No validations
require 'test_helper'
class MainTest < ActionDispatch::IntegrationTest
def test_main
#index looks ok
get '/'
assert_tag(:a, child: "New Post")
assert_select("a[href=/posts/new]")
class PicturesController < ApplicationController
def index
if confirm_params_or_redirect(params)
redirect_to root_path(:view => @view, :filter => @filter) and return
end
Picture.find(@view, @filter)
end
def get_file_from_disk(self):
first_time = False
if not os.path.exists(CONFIG_DIR):
os.mkdir(CONFIG_DIR)
first_time = True
if not os.path.exists(DIARY_FILE):
file = open(DIARY_FILE, 'w')
file.close()
first_time = True
@andrzejkrzywda
andrzejkrzywda / gist:974275
Created May 16, 2011 11:30
cucumber vs bbq
Scenario: Artist creates an art work
Given I am a registered artist
And I follow the add new artwork link from the dashboard
When I fill the form with the artwork data
And I upload a picture
Then I should see a confirmation message telling me that the artwork was added to my collection
scenario "artist creates an art work" do
artist = TestUser.new
artist.go_to_new_artwork_page
@andrzejkrzywda
andrzejkrzywda / object_key_test.rb
Created July 14, 2011 09:53 — forked from paneq/test.rb
Which version do you prefere?
require 'test/unit'
class KeyTest < Test::Unit::TestCase
def test_key
object = Object.new
assert_equal(:submit, object_key(object))
def object.persisted?; true end
assert_equal(:update, object_key(object))