1
0
Fork 0

Fix some law of demeter violations

This commit is contained in:
Andrew Tomaka 2015-07-20 15:12:26 -04:00
parent 95fe1fab7f
commit 86e1cd891c
7 changed files with 11 additions and 3 deletions

View File

@ -2,6 +2,8 @@ class Post < ActiveRecord::Base
belongs_to :user
belongs_to :subcreddit
delegate :username, to: :user, prefix: true
validates :title,
presence: true,
length: { maximum: 300 }

View File

@ -8,6 +8,8 @@ class Subcreddit < ActiveRecord::Base
attr_accessor :closed
delegate :username, to: :owner, prefix: true
before_save :set_closed_at
validates :name,

View File

@ -18,4 +18,4 @@
.title Moderators
.box
ul
li= @subcreddit.owner.username
li= @subcreddit.owner_username

View File

@ -1,7 +1,7 @@
.posts
.post.show
p.title= link_to @post.title, [@subcreddit, @post]
p.details= "submitted #{distance_of_time_in_words @post.created_at, Time.now} ago by #{@post.user.username}"
p.details= "submitted #{distance_of_time_in_words @post.created_at, Time.now} ago by #{@post.user_username}"
ul.links.list-inline
li= link_to 'XXX comments', ''
li= link_to 'source', ''

View File

@ -7,7 +7,7 @@
li
.post
p.title= link_to post.title, [@subcreddit, post]
p.details= "submitted #{distance_of_time_in_words post.created_at, Time.now} ago by #{post.user.username}"
p.details= "submitted #{distance_of_time_in_words post.created_at, Time.now} ago by #{post.user_username}"
ul.links.list-inline
li= link_to 'XXX comments', ''
li= link_to 'share', ''

View File

@ -6,6 +6,8 @@ describe Post, type: :model do
it { should belong_to(:user) }
it { should belong_to(:subcreddit) }
it { should delegate_method(:username).to(:user).with_prefix }
context 'with valid data' do
it 'should be valid' do
expect(post).to be_valid

View File

@ -7,6 +7,8 @@ describe Subcreddit, type: :model do
it { should belong_to(:owner).class_name('User') }
it { should delegate_method(:username).to(:owner).with_prefix }
context 'with valid data' do
it 'should be valid' do
expect(subcreddit).to be_valid