Permalink
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 c6ee494 commit d95d8feaf6cbfc4167fa57efc29f55b899a2a685 @desi desi committed Nov 5, 2008
@@ -0,0 +1,3 @@
+class StoriesController < ActionController::Base
+ resources_controller_for :stories
+end
View
@@ -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
@@ -35,7 +35,6 @@
#
class Pitch < NewsItem
- aasm_column :status
aasm_initial_state :active
aasm_state :active
View
@@ -35,7 +35,6 @@
#
class Story < NewsItem
- aasm_column :status
aasm_initial_state :draft
aasm_state :draft
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,6 +1,4 @@
--colour
--format specdoc
---loadby mtime
---reverse
--backtrace

0 comments on commit d95d8fe

Please sign in to comment.