Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9362931
Styling code
Sep 5, 2013
597596c
Fix to be able to render new event form
Sep 5, 2013
c3a242e
Add and configure fabrication gem
Sep 5, 2013
cc56c09
Create specs for events_controller and event model
Sep 16, 2013
747561b
Very basic event form, WIP
Sep 16, 2013
47d00ae
Add ruby_version file
vicmaster Sep 16, 2013
d9d040e
Add database cleaner to clean test suite
vicmaster Sep 16, 2013
49c91e1
Quiet Assets turns off the Rails asset pipeline log
vicmaster Sep 16, 2013
5e3e5f6
Implement annotate GEM
vicmaster Sep 16, 2013
2fc53d8
Usage of the annotate gem in the models and routes
vicmaster Sep 16, 2013
9986bf5
Keep with testing and event creation
vicmaster Sep 17, 2013
c40b0b8
Merge branch 'master' into feature_create_event
vicmaster Sep 18, 2013
0e54fc4
Refactor specs WIP
vicmaster Sep 19, 2013
7217d11
Refactor rspec WIP
vicmaster Sep 19, 2013
98e7458
Merge branch 'master' into feature_create_event
vicmaster Sep 19, 2013
bb61d98
Add last modifications to user model and the schema
vicmaster Oct 3, 2013
fbee4cf
add fivemat to the gemfile
Oct 3, 2013
58212df
pry debugger gem
Oct 3, 2013
96b4c8a
complete event asociation with user
Oct 3, 2013
6159650
Merge branch 'master' into feature_create_event
Oct 3, 2013
5834b22
Remove weird message from database schema
Oct 3, 2013
7764419
Remove weird message from database schema
Oct 3, 2013
41df701
Remove thin server
vicmaster Nov 7, 2013
59dee52
Merge github.com:hackd/hackd.mx into feature_create_event
vicmaster Nov 7, 2013
7ebb5de
Merge branch 'feature_create_event' of github.com:hackd/hackd.mx into…
vicmaster Nov 7, 2013
303d96e
users are able to create events
Nov 7, 2013
802b3d3
specs fixed and fivemat moved to test group
Nov 7, 2013
dace2d7
Merge branch 'master' into feature_create_event
Nov 7, 2013
15be8a6
use expectation and also use the before filter on controller
Nov 7, 2013
27bfcf6
Remove action in update method when fails
vicmaster Nov 13, 2013
6cd53bc
Remove inconsistent labels and fields names
vicmaster Nov 13, 2013
cccdedd
Add expect implementation instead of should
vicmaster Nov 13, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ group :development, :test do
gem 'rspec-rails', '~> 2.0'
gem 'capybara-webkit'
gem 'capybara'
gem 'fabrication'
gem 'database_cleaner'
gem 'pry-debugger'
gem 'git-duet'
gem 'dotenv'
end

group :development do
gem 'git-pair'
gem 'pry'
gem 'quiet_assets'
gem 'annotate', ">=2.5.0"
gem 'rails-erd'
end

Expand All @@ -35,5 +40,6 @@ group :doc do
end

group :test do
gem 'fivemat'
gem 'simplecov', require: false
end
23 changes: 23 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
angularjs-rails (1.0.7)
annotate (2.5.0)
rake
arel (4.0.0)
atomic (1.1.10)
builder (3.1.4)
Expand All @@ -47,13 +49,23 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.6.2)
columnize (0.3.6)
database_cleaner (1.1.1)
debugger (1.6.2)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.2.3)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.2.3)
diff-lcs (1.2.1)
dotenv (0.9.0)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
fabrication (2.8.0)
faraday (0.8.8)
multipart-post (~> 1.2.0)
fivemat (1.2.1)
git-duet (0.1.3)
git-pair (0.1.0)
haml (4.0.3)
Expand Down Expand Up @@ -107,8 +119,13 @@ GEM
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
pry-debugger (0.2.2)
debugger (~> 1.3)
pry (~> 0.9.10)
puma (2.6.0)
rack (>= 1.1, < 2.0)
quiet_assets (1.0.2)
railties (>= 3.1, < 5.0)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
Expand Down Expand Up @@ -188,10 +205,14 @@ PLATFORMS

DEPENDENCIES
angularjs-rails
annotate (>= 2.5.0)
capybara
capybara-webkit
coffee-rails (~> 4.0.0)
database_cleaner
dotenv
fabrication
fivemat
git-duet
git-pair
haml-rails (~> 0.4)
Expand All @@ -200,7 +221,9 @@ DEPENDENCIES
omniauth-github
pg
pry
pry-debugger
puma (~> 2.6.0)
quiet_assets
rails (= 4.0.0)
rails-erd
rspec-rails (~> 2.0)
Expand Down
36 changes: 22 additions & 14 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
class EventsController < ApplicationController
before_action :find_event, only: [ :edit, :show ]
before_action :find_event, only: [ :edit, :show, :update ]
before_action :event_params, only: [ :update ]

def index
@events = Event.all
end

def new
end

def edit
@event = Event.new
end

def show
end

def create
@event = current_user.events.new event_params
if current_user.save
flash[:notice] = 'Successfully created'
redirect_to events_path
else
flash[:error] = 'Something went wrong'
render new_event_path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At line 37 you use render action: 'edit' and here you use a path helper. Isn't this somewhat inconsistent?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

end
end

def update
def edit
@event = Event.find(params[:id])
if @event.update_attributes(@params)
flash[:notice] = "Event updated successfully"
end

def update
if @event.update event_params
flash[:notice] = "Event updated successfully"
redirect_to events_path
else
flash[:notice] = "Event wasn't updated as expected"
redirect_to :back
flash[:notice] = "Event wasn't updated as expected"
render :edit
end
end

def destroy
end

private

def event_params
@params = params.require(:event).permit(:name, :details, :location)
@params = params.require(:event).permit!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this one, but does this allow mass-assignment of time-stamp fields? (i.e. created_at, updated_at)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private: The attribute cannot be changed via mass-assignment, I think we are good here but not really sure, let's discuss about it...what do you think @joiggama ?

Copy link
Contributor

@joiggama joiggama Sep 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory it does allow mass-assignment of anything within event.

🍭

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL 3 years later

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL

David Vega mailto:notifications@github.com
September 7, 2016 at 6:13 PM

In app/controllers/events_controller.rb
#24 (comment):

def event_params

  • @params = params.require(:event).permit(:name, :details, :location)
  • @params = params.require(:event).permit!

LOL 3 years later


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/vicmaster/old.hackd.mx/pull/24/files/15be8a675569ac900521d74bdb0126fc0db0beaf#r77921456,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AETXSsxD1M-0MvaVgs_EGMe0LTgm4j1Aks5qn0UpgaJpZM4BD1VP.

Ruben Betancourt
Agile Coach & Project Manager at TangoSource LLC.
Website http://tangosource.com| Facebook
https://www.facebook.com/pages/TangoSource/309331769099987?fref=ts |
Blog http://tangosource.com/blog |http://tangosource.comTwitter
https://twitter.com/tangosource

end

def find_event
@event = Event.find(params[:id])
end


@event = Event.find(params[:id])
end
end
22 changes: 21 additions & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# == Schema Information
#
# Table name: events
#
# id :integer not null, primary key
# name :string(255)
# details :text
# user_id :integer
# latitude :string(255)
# longitude :string(255)
# location_name :string(255)
# scheduled_at :datetime
# created_at :datetime
# updated_at :datetime
#

class Event < ActiveRecord::Base
validates_presence_of :name, :details, :user_id
belongs_to :user
validates_presence_of :name, :user_id

# Note: Make sure that this doesn't conflict with ActiveRecord
attr_accessor :where
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class User < ActiveRecord::Base
has_many :events

def self.create_with_omniauth auth
create! do |user|
Expand Down
4 changes: 2 additions & 2 deletions app/views/events/_event.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
.name
= event.name
%span
%em
%em
created by:
= event.user_id
publish date:
= event.created_at.strftime('%y/%d/%m')
.details
= event.details

= link_to 'Edit', edit_event_path(event)
= link_to 'Show', event_path(event)
= link_to 'Back', events_path
25 changes: 18 additions & 7 deletions app/views/events/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
= render partial: 'layouts/error_messages', locals: { resource: @event}

= form_for @event do |f|
= f.label :name
= f.text_field :name
= f.label :details
= f.text_area :details
= f.label :location
= f.text_field :location_name
= f.submit
%p
= f.label :event_name
= f.text_field :event_name
%p
= f.label :information
= f.text_area :information_details
%p
= f.label :location_name
= f.text_field :location_name
%p
= f.label :where
= f.text_field :where
%p
= f.label :when
= f.text_field :scheduled_at
%p
= f.submit
2 changes: 1 addition & 1 deletion app/views/home/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
%h1 Hackd.mx
%p This is a dummy home page
%p This is a dummy home page
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module Hackd
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
Expand All @@ -15,6 +14,7 @@ class Application < Rails::Application
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
#config.quiet_assets = false

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/fabrication.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fabrication.configure do |config|
config.fabricator_path = 'spec/fabricators'
config.path_prefix = Rails.root
config.sequence_start = 10000
end
15 changes: 15 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@

root to: 'events#index'
end
#== Route Map
# Generated on 16 Sep 2013 18:00
#
# github_callback GET /auth/github/callback(.:format) sessions#create
# sessions POST /sessions(.:format) sessions#create
# session DELETE /sessions/:id(.:format) sessions#destroy
# events GET /events(.:format) events#index
# POST /events(.:format) events#create
# new_event GET /events/new(.:format) events#new
# edit_event GET /events/:id/edit(.:format) events#edit
# event GET /events/:id(.:format) events#show
# PATCH /events/:id(.:format) events#update
# PUT /events/:id(.:format) events#update
# DELETE /events/:id(.:format) events#destroy
# root GET / events#index
3 changes: 0 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

ActiveRecord::Schema.define(version: 20131017021425) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "events", force: true do |t|
t.string "name"
t.text "details"
Expand Down
Loading