Skip to content

Commit

Permalink
Remove some unnecessary code from note model
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Francois committed Sep 26, 2013
1 parent 954216b commit 2cb2fb3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
7 changes: 3 additions & 4 deletions app/controllers/admin/notes_controller.rb
Expand Up @@ -3,7 +3,7 @@ module Admin; end
class Admin::NotesController < Admin::BaseController
layout "administration"
cache_sweeper :blog_sweeper

def index; redirect_to :action => 'new' ; end
def new; new_or_edit; end
def edit; new_or_edit; end
Expand All @@ -21,7 +21,6 @@ def get_or_build_status
note.text_filter = current_user.default_text_filter
note.published = true
note.published_at = Time.now
note.push_to_twitter = true
end
end

Expand Down Expand Up @@ -51,8 +50,8 @@ def new_or_edit

if @note.save
flash[:notice] = _("Note was successfully %s.", message)
if params[:note][:push_to_twitter] and params[:note][:push_to_twitter] != "0" and (@note.twitter_id.nil? or @note.twitter_id.empty?)
unless @note.send_to_twitter
if params[:note][:push_to_twitter] && @note.twitter_id.blank?
unless @note.send_to_twitter
flash[:notice] = nil
flash[:error] = _("Oooops something wrong happened")
end
Expand Down
10 changes: 4 additions & 6 deletions app/models/note.rb
Expand Up @@ -7,15 +7,14 @@ class Note < Content

serialize :settings, Hash

setting :twitter_id, :string, ""
setting :in_reply_to_status_id, :string, ""
setting :in_reply_to_protected, :boolean, false
setting :in_reply_to_message, :string, ""
setting :twitter_id, :string, ""
setting :in_reply_to_status_id, :string, ""
setting :in_reply_to_protected, :boolean, false
setting :in_reply_to_message, :string, ""

belongs_to :user
validates_presence_of :body
validates_uniqueness_of :permalink, :guid
attr_accessor :push_to_twitter

after_create :set_permalink, :shorten_url
before_create :create_guid
Expand Down Expand Up @@ -63,7 +62,6 @@ def twitter_message
end

def send_to_twitter
return false unless self.push_to_twitter # Then, what are we doing here?!
return false unless Blog.default.has_twitter_configured?
return false unless self.user.has_twitter_configured?

Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/notes/new.html.erb
Expand Up @@ -13,11 +13,11 @@
<legend><%= _("Publish settings") %></legend>
<%= twitter_disabled_message(this_blog, current_user) %>
<label for="note_push_to_twitter" class='checkbox'>
<%= check_box 'note', 'push_to_twitter', {disabled: twitter_available?(this_blog, current_user)} %>
<%= check_box_tag 'push_to_twitter', true, @note.twitter_id.blank?, {disabled: !twitter_available?(this_blog, current_user)} %>
<%= _("POSSE to Twitter")%>
</label>
<label for="note_in_reply_to_status_id"><%= _("In reply to")%></label>
<%= text_field 'note', 'in_reply_to_status_id', :class => 'input-block-level', :placeholder => _("tweet id like 123456"), disabled: twitter_available?(this_blog, current_user) %>
<%= text_field 'note', 'in_reply_to_status_id', :class => 'input-block-level', :placeholder => _("tweet id like 123456"), disabled: !twitter_available?(this_blog, current_user) %>
<label for="note_permalink"><%= _("Permanent link")%></label>
<%= text_field 'note', 'permalink', :class => 'input-block-level' %>
<label for='note_published' class='checkbox'>
Expand Down
21 changes: 12 additions & 9 deletions spec/models/note_spec.rb
Expand Up @@ -71,25 +71,28 @@
end

describe :send_to_twitter do
context "with a push to twitter note" do
let(:note) { build(:note, push_to_twitter: false) }
let(:note) { build(:note) }
context "with twitter configured for blog and user" do
before(:each) do
Blog.any_instance.should_receive(:has_twitter_configured?).and_return(true)
User.any_instance.should_receive(:has_twitter_configured?).and_return(true)
end

it { expect(note.send_to_twitter).to be_false }
end

context "with a push to twitter note" do
before(:each) { Blog.any_instance.should_receive(:has_twitter_configured?).and_return(false) }
let(:note) { build(:note, push_to_twitter: true) }

context "with twitter not configured for blog" do
before(:each) do
Blog.any_instance.should_receive(:has_twitter_configured?).and_return(false)
end
it { expect(note.send_to_twitter).to be_false }
end

context "with a push to twitter note" do
context "with a twitter configured for blog but not user" do
before(:each) do
Blog.any_instance.should_receive(:has_twitter_configured?).and_return(true)
User.any_instance.should_receive(:has_twitter_configured?).and_return(false)
end

let(:note) { build(:note, push_to_twitter: true) }
it { expect(note.send_to_twitter).to be_false }
end

Expand Down

0 comments on commit 2cb2fb3

Please sign in to comment.