[Logilogi-svn] SF.net SVN: logilogi:[1611] projects/loglog/trunk
Status: Beta
Brought to you by:
wybow
|
From: <wy...@us...> - 2009-10-04 22:04:47
|
Revision: 1611
http://logilogi.svn.sourceforge.net/logilogi/?rev=1611&view=rev
Author: wybow
Date: 2009-10-04 22:04:37 +0000 (Sun, 04 Oct 2009)
Log Message:
-----------
Updated with tests and auto-channel if non-existant
Modified Paths:
--------------
projects/loglog/trunk/app/controllers/application_controller.rb
projects/loglog/trunk/app/controllers/channels_controller.rb
projects/loglog/trunk/app/controllers/feeds_controller.rb
projects/loglog/trunk/app/models/app.rb
projects/loglog/trunk/app/models/message.rb
projects/loglog/trunk/app/views/feeds/show.atom.builder
projects/loglog/trunk/test/unit/app_test.rb
Modified: projects/loglog/trunk/app/controllers/application_controller.rb
===================================================================
--- projects/loglog/trunk/app/controllers/application_controller.rb 2009-10-04 18:39:41 UTC (rev 1610)
+++ projects/loglog/trunk/app/controllers/application_controller.rb 2009-10-04 22:04:37 UTC (rev 1611)
@@ -20,7 +20,7 @@
end
def find_channel
- @channel = @app.channels.find_by_name(params[:channel_id])
+ @channel = @app.channels.find_or_build_by_name(params[:channel_id])
end
# Returns the current app session, see authlogic.
Modified: projects/loglog/trunk/app/controllers/channels_controller.rb
===================================================================
--- projects/loglog/trunk/app/controllers/channels_controller.rb 2009-10-04 18:39:41 UTC (rev 1610)
+++ projects/loglog/trunk/app/controllers/channels_controller.rb 2009-10-04 22:04:37 UTC (rev 1611)
@@ -25,7 +25,7 @@
### Filter-functions
def find
- @channel = @app.channels.find_by_name(params[:id])
+ @channel = @app.channels.find_or_build_by_name(params[:id])
end
### Bodies
Modified: projects/loglog/trunk/app/controllers/feeds_controller.rb
===================================================================
--- projects/loglog/trunk/app/controllers/feeds_controller.rb 2009-10-04 18:39:41 UTC (rev 1610)
+++ projects/loglog/trunk/app/controllers/feeds_controller.rb 2009-10-04 22:04:37 UTC (rev 1611)
@@ -19,7 +19,7 @@
### REST-methods
def show
- @messages = @channel.messages
+ @messages = @channel.messages.find(:all, :order => "created_at DESC", :limit => 30)
respond_to do |format|
format.atom do
@title = 'LogLog ' + @channel.name + ' channel'
Modified: projects/loglog/trunk/app/models/app.rb
===================================================================
--- projects/loglog/trunk/app/models/app.rb 2009-10-04 18:39:41 UTC (rev 1610)
+++ projects/loglog/trunk/app/models/app.rb 2009-10-04 22:04:37 UTC (rev 1611)
@@ -20,7 +20,16 @@
### Relationships
- has_many :channels, :dependent => :destroy
+ has_many :channels, :dependent => :destroy do
+ def find_or_build_by_name(name)
+ channel = find_by_name(name)
+ if channel
+ return channel
+ else
+ return Channel.new(:app => proxy_owner, :name => name)
+ end
+ end
+ end
### Filters
@@ -37,17 +46,6 @@
:message => "is incorrect, please check for typo's"
validates_length_of :password, :minimum => 6, :on => :create, :allow_nil => true
- ### Methods
-
- def or_new_channel_for_name(name)
- c = self.channels.find_by_name(name)
- if c.nil?
- return Channel.new(:app => self, :name => name)
- else
- return c
- end
- end
-
### Filter-functions (some are public)
protected
Modified: projects/loglog/trunk/app/models/message.rb
===================================================================
--- projects/loglog/trunk/app/models/message.rb 2009-10-04 18:39:41 UTC (rev 1610)
+++ projects/loglog/trunk/app/models/message.rb 2009-10-04 22:04:37 UTC (rev 1611)
@@ -35,6 +35,6 @@
### Methods
def set_channel_from(app, channel_name)
- self.channel = app.or_new_channel_for_name(channel_name)
+ self.channel = app.channels.find_or_build_by_name(channel_name)
end
end
Modified: projects/loglog/trunk/app/views/feeds/show.atom.builder
===================================================================
--- projects/loglog/trunk/app/views/feeds/show.atom.builder 2009-10-04 18:39:41 UTC (rev 1610)
+++ projects/loglog/trunk/app/views/feeds/show.atom.builder 2009-10-04 22:04:37 UTC (rev 1611)
@@ -1,6 +1,10 @@
atom_feed do |feed|
feed.title(@title)
- feed.updated((@messages.first.created_at))
+ if @messages.empty?
+ feed.updated(Time.now)
+ else
+ feed.updated(@messages.first.created_at)
+ end
feed.link "rel" => "self",
"href" => url_for(:only_path => false, :format => 'atom')
feed.link "rel" => "alternate",
Modified: projects/loglog/trunk/test/unit/app_test.rb
===================================================================
--- projects/loglog/trunk/test/unit/app_test.rb 2009-10-04 18:39:41 UTC (rev 1610)
+++ projects/loglog/trunk/test/unit/app_test.rb 2009-10-04 22:04:37 UTC (rev 1611)
@@ -16,15 +16,15 @@
class AppTest < ActiveSupport::TestCase
fixtures :all
- def test_or_new_channel_for_name
+ def test_channels_find_or_build_by_name
a = apps(:enll)
# existing
assert_equal channels(:logis),
- a.or_new_channel_for_name('logis')
+ a.channels.find_or_build_by_name('logis')
# new
assert_equal 'far_cries',
- a.or_new_channel_for_name('far_cries').name
+ a.channels.find_or_build_by_name('far_cries').name
end
def test_assert_persistence_token
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|