Browse files

Desi and Stephen - Hot Controller Lovin'. AASM patch for shallow even…

…t clone, so we can have events of the same name on two different models.
  • Loading branch information...
1 parent a9ad6d2 commit a54af3a60dbac2bc57ca5fecc651a776c71e1dd3 @desi desi committed Nov 5, 2008
View
3 app/controllers/stories_controller.rb
@@ -0,0 +1,3 @@
+class StoriesController < ActionController::Base
+ resources_controller_for :stories
+end
View
11 app/models/news_item.rb
@@ -36,14 +36,9 @@
class NewsItem < ActiveRecord::Base
include HasTopics
- include AASM
- class <<self
- alias invasive_inherited_from_aasm inherited
- def inherited(child)
- invasive_inherited_from_aasm(child)
- super
- end
- end
+ include AASMWithFixes
+
+ aasm_column :status
belongs_to :user
has_attached_file :featured_image,
View
1 app/models/pitch.rb
@@ -35,7 +35,6 @@
#
class Pitch < NewsItem
- aasm_column :status
aasm_initial_state :active
aasm_state :active
View
1 app/models/story.rb
@@ -35,7 +35,6 @@
#
class Story < NewsItem
- aasm_column :status
aasm_initial_state :draft
aasm_state :draft
View
10 app/models/user.rb
@@ -40,14 +40,8 @@
class User < ActiveRecord::Base
include HasTopics
- include AASM
- class <<self
- alias invasive_inherited_from_aasm inherited
- def inherited(child)
- invasive_inherited_from_aasm(child)
- super
- end
- end
+ include AASMWithFixes
+
aasm_column :status
aasm_initial_state :active
aasm_state :active
View
10 config/routes.rb
@@ -2,15 +2,9 @@
map.root :controller => 'homes', :action => 'show'
map.resources :news_items, :collection => {:search => :any, :sort_options => :get}
- map.resources :donations
- map.resources :affiliations
+ map.resources :donations, :affiliations, :pledges, :profiles, :pages, :stories
map.resources :tips, :has_many => :affiliations
- map.resources :pledges
- map.resources :pitches, :member => {:feature => :post} do |pitch|
- pitch.resource :story, :controller => :story
- end
- map.resources :profiles
- map.resources :pages
+ map.resources :pitches, :member => {:feature => :post}
# TODO: remove when done
map.resources :ui
View
9 db/migrate/20081104210705_add_news_item_id_to_news_item.rb
@@ -0,0 +1,9 @@
+class AddNewsItemIdToNewsItem < ActiveRecord::Migration
+ def self.up
+ add_column :news_items, :news_item_id, :integer
+ end
+
+ def self.down
+ drop_column :news_items, :news_item_id
+ end
+end
View
14 lib/aasm_with_fixes.rb
@@ -0,0 +1,14 @@
+module AASMWithFixes
+ def self.included(base)
+ base.send(:include, AASM)
+ base.module_eval do
+ class << self
+ def inherited(child)
+ AASM::StateMachine[child] = AASM::StateMachine[self].clone
+ AASM::StateMachine[child].events = AASM::StateMachine[self].events.clone
+ super
+ end
+ end
+ end
+ end
+end
View
17 spec/controllers/stories_controller_spec.rb
@@ -0,0 +1,17 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe StoriesController do
+
+ route_matches('/stories/1/edit', :get, :controller => 'stories',
+ :action => 'edit',
+ :id => "1")
+
+ route_matches('/stories/1', :put, :controller => 'stories',
+ :action => 'update',
+ :id => "1")
+
+ route_matches('/stories/1', :get, :controller => 'stories',
+ :action => 'show',
+ :id => "1")
+
+end
View
2 spec/models/pitch_spec.rb
@@ -502,7 +502,7 @@
end
end
describe "via accept!" do
- it "should create a story on fund!" do
+ it "should create a story" do
p = Factory(:pitch)
p.accept!
p.story.should_not be_nil
View
19 spec/models/story_spec.rb
@@ -1,6 +1,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Story do
+
requires_presence_of Story, :headline
requires_presence_of Story, :location
@@ -25,25 +26,27 @@
end
it "should transition from 'draft' to 'fact_check'" do
+ @story.update_attribute(:status,'draft')
@story.verify!
@story.should be_fact_check
end
+ it "should transition from 'fact_check' to 'ready'" do
+ @story.update_attribute(:status,'fact_check')
+ @story.accept!
+ @story.should be_ready
+ end
+
it "should transition from 'fact_check' to 'draft'" do
- @story.verify!
+ @story.update_attribute(:status,'fact_check')
@story.reject!
@story.should be_draft
end
- it "should transition from 'fact_check' to 'ready'" do
- @story.verify!
- @story.accept!
- @story.should be_ready
- end
+
it "should transition from 'ready' to 'published'" do
- @story.verify!
- @story.accept!
+ @story.update_attribute(:status,'ready')
@story.publish!
@story.should be_published
end
View
2 spec/spec.opts
@@ -1,6 +1,4 @@
--colour
--format specdoc
---loadby mtime
---reverse
--backtrace

0 comments on commit a54af3a

Please sign in to comment.