Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes for Loccasions 7: Foreman, Occasions, Inherited Resources
- Loading branch information
Showing
21 changed files
with
219 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Place all the styles related to the occasions controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ | ||
|
||
.coordinate_input { | ||
float:left; | ||
padding: 0 0.5em; | ||
} | ||
|
||
.coordinate_input input, .date_field input{ | ||
float:left; | ||
width: 5em; | ||
padding-right: .5em; | ||
} | ||
.note_field { | ||
clear: both; | ||
} | ||
.note_field textarea { | ||
width: 35em; | ||
height: 5em; | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class OccasionsController < InheritedResources::Base | ||
belongs_to :event | ||
actions :all, :except => [:show, :index] | ||
|
||
|
||
# Need to override this from inherited_resources | ||
# to scope the association chain to the current_user | ||
def begin_of_association_chain | ||
current_user | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module OccasionsHelper | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Occasion | ||
include Mongoid::Document | ||
field :occurred_at, :type => Time | ||
field :latitude, :type => Float | ||
field :longitude, :type => Float | ||
field :note, :type => String | ||
embedded_in :event, :inverse_of => :occasions | ||
validates :occurred_at, :latitude, :longitude, :presence => true | ||
|
||
attr_accessible :occurred_at, :latitude, :longitude, :note | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
%span.del_form | ||
=button_to "X", event, :confirm => "Are you sure?", :method => :delete | ||
%span.event_name | ||
= link_to event.name, edit_event_path(event) | ||
%span.event_details | ||
= link_to "Show Details", event_path(event) | ||
%span.event_description= event.description |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
%h2= @event.name | ||
.description= @event.description | ||
%div#map.twelve.columns.alpha | ||
%ul#occasions.four.columns.omega | ||
- for occasion in @event.occasions | ||
%li | ||
= render :partial => "occasions/occasion", :locals => {:occasion => occasion} | ||
%div.clear | ||
%div#occasion_form | ||
= form_for [@event, current_user.events.find(@event.id).occasions.build()] do |f| | ||
%div.coordinate_input | ||
= f.label :latitude | ||
= f.text_field :latitude | ||
%div.coordinate_input | ||
= f.label :longitude | ||
= f.text_field :longitude | ||
%div.date_field | ||
= f.label :occurred_at | ||
= f.text_field :occurred_at | ||
%div.note_field | ||
= f.label :note | ||
= f.text_area :note | ||
= f.submit "Add" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
%span.del_form | ||
=button_to "X", [occasion.event,occasion], :confirm => "Are you sure?", :method => :delete | ||
%span.occasion_name | ||
= link_to occasion.occurred_at.to_s(:short), edit_event_occasion_path(@event, occasion) | ||
%span.occasion_note | ||
= occasion.note |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module MongoidActions | ||
def collection | ||
get_collection_ivar || set_collection_ivar(end_of_association_chain.all) | ||
end | ||
end | ||
|
||
InheritedResources::Base.send :include, MongoidActions |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Loccasions::Application.routes.draw do | ||
|
||
devise_for :users | ||
resources :events | ||
resources :events do | ||
resources :occasions | ||
end | ||
get 'events' => 'events#index', :as => :user_root | ||
root :to => "home#index" | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'spec_helper' | ||
|
||
feature 'Add Occasion', %q{ | ||
As a registered user | ||
I want to add an Occasion to an Event | ||
} do | ||
background do | ||
@user = Factory(:user) | ||
login_user @user | ||
@event = Factory(:event,:user => @user ) | ||
visit event_path(@event) | ||
end | ||
scenario "Add Occasion" do | ||
page.should_not have_css("ul#occasions > li") | ||
fill_in "Latitude", :with => 35.22 | ||
fill_in "Longitude", :with => -85.22 | ||
fill_in "Note", :with => "This is my new occasion" | ||
fill_in "Occurred at", :with => '2011-11-03' | ||
click_button "Add" | ||
page.should have_css("ul#occasions > li", :count => 1) | ||
page.should have_content("This is my new occasion") | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'spec_helper' | ||
|
||
feature "Delete Occasion", %q{ | ||
As a registered user, | ||
I want to delete an occasion from an event | ||
} do | ||
|
||
background do | ||
Capybara.current_driver = :selenium | ||
@occasion = Factory(:occasion) | ||
login_user @occasion.event.user | ||
visit event_path(@occasion.event) | ||
end | ||
|
||
after do | ||
Capybara.use_default_driver | ||
end | ||
|
||
scenario "Delete Occasion" do | ||
page.should have_content("Test Occasion") | ||
page.should have_selector("form[action='/events/#{@occasion.event.id}/occasions/#{@occasion.id}'] input[value='delete']") | ||
# auto confirm the dialog | ||
page.execute_script('window.confirm = function() {return true;}') | ||
click_button "X" | ||
page.should_not have_content("Test Occasion") | ||
end | ||
|
||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
|
||
describe "Occasion" do | ||
before do | ||
@occasion = Factory.create(:occasion) | ||
end | ||
it "should have a time and date of occurrance" do | ||
dt = Time.now | ||
@occasion.occurred_at = dt | ||
|
||
@occasion.occurred_at.to_s.should == dt.to_s | ||
end | ||
|
||
it "should have a latitude and longitude" do | ||
@occasion.latitude = -85.000 | ||
@occasion.longitude = 35.3232 | ||
|
||
@occasion.latitude.should == -85.000 | ||
@occasion.longitude.should == 35.3232 | ||
end | ||
|
||
it "should have a note" do | ||
@occasion.note = "This thang went down" | ||
@occasion.note.should == "This thang went down" | ||
end | ||
|
||
describe "validation" do | ||
it "should require a latitude" do | ||
@occasion.latitude = nil | ||
@occasion.should_not be_valid | ||
end | ||
|
||
it "should require a longitude" do | ||
@occasion.longitude = nil | ||
@occasion.should_not be_valid | ||
end | ||
end | ||
end |
This file contains 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