Skip to content

Commit

Permalink
Some basic news functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m committed May 13, 2009
1 parent 81ff297 commit da77626
Show file tree
Hide file tree
Showing 15 changed files with 517 additions and 43 deletions.
13 changes: 11 additions & 2 deletions app/controllers/news_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,14 @@ def destroy
render :text => 'You cannot delete this news item.', :layout => true, :status => 401
end
end

end

def create
@news_item = NewsItem.new(params[:news_item])
if @news_item.save
flash[:notice] = 'Your news has been submitted.'
redirect_to news_path
else
render :action => 'new'
end
end
end
5 changes: 5 additions & 0 deletions app/models/news_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class NewsItem < ActiveRecord::Base

def name; title; end

before_save :update_published_date
def update_published_date
self.published = Time.now if published.nil?
end

class << self
def update_from_feed
if raw_items = get_feed_items
Expand Down
2 changes: 1 addition & 1 deletion app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,4 @@ def self.custom_types
class_eval "include Person::#{mod_name}"
end

end
end
13 changes: 13 additions & 0 deletions app/views/news/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% form_for @news_item, :url => @news_item.new_record? ? news_path : news_item_path(@news_item) do |form| %>
<p>
<%= form.label :title, 'Give your post a concise title:' %>
<%= form.text_field :title %>
</p>
<p>
<%= form.label :body, 'Share your announcement, information, or news here:' %>
<%= form.text_area :body, :rows => 5, :cols => 80 %>
</p>
<p>
<%= form.submit 'Submit News' %>
</p>
<% end %>
3 changes: 3 additions & 0 deletions app/views/news/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h2>Submit News</h2>

<%= render :partial => 'form' %>
4 changes: 3 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@
config.action_controller.session = {
:session_key => "_onebody_session",
:secret => "not so secret - this is only here for the test environment"
}
}

config.threadsafe!
14 changes: 14 additions & 0 deletions db/migrate/20090508010501_update_news_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class UpdateNewsItems < ActiveRecord::Migration
def self.up
change_table :news_items do |t|
t.integer :person_id
t.timestamps
end
end

def self.down
change_table :news_items do |t|
t.remove :person_id, :created_at, :updated_at
end
end
end
17 changes: 9 additions & 8 deletions features/news/submit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ Feature: Users Submit News
Background:
Given I am signed in as a user

Scenario: User sees no news when there are no submissions
Scenario: User sees no news when there are no posts
Given there are no news items
When I go to news
Then I should see "No news is available at this time."

Scenario: User sees news when there is a submission
Scenario: User sees news when there is a post
Given there is a news item with title "A News Post" and body "This is the first news post."
When I go to news
Then I should see "A News Post"
And I should see "This is the first news post."

Scenario: User submit news
Scenario: User submits news
When I go to new news submission
Then I should see "Title"
And I should see "Body"
When I fill in "Title" with "My News Item"
And I fill in "Body" with "This is my first news post."
And I fill in "Give your post a concise title" with "My News Item"
And I fill in "Share your announcement, information, or news here" with "This is my first news post."
And I press "Submit News"
Then I should see "Your news post has been submitted."
Then I should see "Your news has been submitted."
When I go to news
Then I should see "My News Item"
And I should see "This is my first news post."

# Scenario: User edit items they have submitted
24 changes: 12 additions & 12 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
require 'cucumber/rails/rspec'
require 'webrat/core/matchers'

require 'spec/mocks/framework'
require 'spec/mocks/extensions'

World(Spec::Mocks::ExampleMethods)

Before do
$rspec_stubs ||= Spec::Mocks::Space.new
end

After do
$rspec_stubs.reset_all
end
# require 'spec/mocks/framework'
# require 'spec/mocks/extensions'
#
# World(Spec::Mocks::ExampleMethods)
#
# Before do
# $rspec_stubs ||= Spec::Mocks::Space.new
# end
#
# After do
# $rspec_stubs.reset_all
# end
27 changes: 12 additions & 15 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ module NavigationHelpers
def path_to(page_name)
case page_name

when /the homepage/
'/'
when 'news'
news_path
when 'new news submission'
new_news_item_path

when 'news'
news_path
when 'new news submission'
new_news_item_path

# Add more mappings here.
# Here is a more fancy example:
#
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))
# Add more mappings here.
# Here is a more fancy example:
#
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))

else
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
"Now, go and add a mapping in #{__FILE__}"
else
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end
Expand Down
Loading

0 comments on commit da77626

Please sign in to comment.