diff --git a/.gitignore b/.gitignore index 26cff94..074b6db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -/.bundle -/db/*.sqlite3 -/log/*.log -/tmp -/bin +.bundle +db/*.sqlite3 +log +*.log +tmp +bin diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..9c2c1b4 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour --profile --order random diff --git a/Gemfile b/Gemfile index 1af7680..8fd8d5d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,45 +1,25 @@ source 'https://rubygems.org/' gem 'rails', '3.2.7' - -# Bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' - gem 'sqlite3' - +gem 'jquery-rails' +gem "paperclip" +gem 'sorcery' +gem 'haml-rails' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' - - # See https://github.com/sstephenson/execjs#readme for more supported runtimes - # gem 'therubyracer', :platforms => :ruby - gem 'uglifier', '>= 1.0.3' gem "twitter-bootstrap-rails", "~> 2.1.3" end -gem 'jquery-rails' - -# To use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.0.0' - -# To use Jbuilder templates for JSON -# gem 'jbuilder' - -# Use unicorn as the app server -# gem 'unicorn' - -# Deploy with Capistrano -# gem 'capistrano' - -# To use debugger -# gem 'debugger' -gem "paperclip" -gem 'sorcery' -gem 'haml-rails' +group :test do + gem 'rspec-rails' + gem 'shoulda-matchers' +end group :development do gem 'hpricot' diff --git a/Gemfile.lock b/Gemfile.lock index 25999ea..34c7d2c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,8 +30,8 @@ GEM multi_json (~> 1.0) arel (3.0.2) bcrypt-ruby (3.0.1) - builder (3.0.0) - cocaine (0.2.1) + builder (3.0.3) + cocaine (0.3.0) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -40,26 +40,27 @@ GEM execjs coffee-script-source (1.3.3) commonjs (0.2.6) + diff-lcs (1.1.3) erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) - faraday (0.8.1) + faraday (0.8.4) multipart-post (~> 1.1) haml (3.1.7) - haml-rails (0.3.4) - actionpack (~> 3.0) - activesupport (~> 3.0) - haml (~> 3.0) - railties (~> 3.0) + haml-rails (0.3.5) + actionpack (>= 3.1, < 4.1) + activesupport (>= 3.1, < 4.1) + haml (~> 3.1) + railties (>= 3.1, < 4.1) hike (1.2.1) hpricot (0.8.6) httpauth (0.1) - i18n (0.6.0) + i18n (0.6.1) journey (1.0.4) - jquery-rails (2.0.2) - railties (>= 3.2.0, < 5.0) + jquery-rails (2.1.2) + railties (>= 3.1.0, < 5.0) thor (~> 0.14) - json (1.7.4) + json (1.7.5) less (2.2.2) commonjs (~> 0.2.6) less-rails (2.2.3) @@ -73,12 +74,12 @@ GEM mime-types (1.19) multi_json (1.3.6) multipart-post (1.1.5) - oauth (0.4.6) + oauth (0.4.7) oauth2 (0.6.1) faraday (~> 0.7) httpauth (~> 0.1) multi_json (~> 1.3) - paperclip (3.1.4) + paperclip (3.2.0) activemodel (>= 3.0.0) activerecord (>= 3.0.0) activesupport (>= 3.0.0) @@ -110,14 +111,29 @@ GEM rake (0.9.2.2) rdoc (3.12) json (~> 1.4) + rspec (2.11.0) + rspec-core (~> 2.11.0) + rspec-expectations (~> 2.11.0) + rspec-mocks (~> 2.11.0) + rspec-core (2.11.1) + rspec-expectations (2.11.3) + diff-lcs (~> 1.1.3) + rspec-mocks (2.11.2) + rspec-rails (2.11.0) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec (~> 2.11.0) ruby_parser (2.3.1) sexp_processor (~> 3.0) - sass (3.1.20) + sass (3.2.1) sass-rails (3.2.5) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) sexp_processor (3.2.0) + shoulda-matchers (1.3.0) + activesupport (>= 3.0.0) sorcery (0.7.13) bcrypt-ruby (~> 3.0.0) oauth (~> 0.4.4) @@ -129,7 +145,7 @@ GEM sqlite3 (1.3.6) therubyracer (0.10.2) libv8 (~> 3.3.10) - thor (0.15.4) + thor (0.16.0) tilt (1.3.3) treetop (1.4.10) polyglot @@ -140,9 +156,9 @@ GEM railties (>= 3.1) therubyracer (~> 0.10.2) tzinfo (0.3.33) - uglifier (1.2.7) + uglifier (1.3.0) execjs (>= 0.3.0) - multi_json (~> 1.3) + multi_json (~> 1.0, >= 1.0.2) PLATFORMS ruby @@ -154,8 +170,10 @@ DEPENDENCIES jquery-rails paperclip rails (= 3.2.7) + rspec-rails ruby_parser sass-rails (~> 3.2.3) + shoulda-matchers sorcery sqlite3 twitter-bootstrap-rails (~> 2.1.3) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index b14b449..a7cb489 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,5 +1,4 @@ class TagsController < ApplicationController - has_many :taggings, :dependant => :destroy def index @articles = Article.all end @@ -7,6 +6,4 @@ def index def show @tag = Tag.find(params[:id]) end - - end diff --git a/app/models/article.rb b/app/models/article.rb index 728e6b7..d9320cf 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -5,25 +5,21 @@ class Article < ActiveRecord::Base has_many :tags, :through => :taggings has_attached_file :image - def tag_list self.tags.collect do |tag| tag.name end.join(", ") end - - - def tag_list=(tags_string) self.taggings.destroy_all tag_names = tags_string.split(",").collect{|s| s.strip.downcase}.uniq tag_names.each do |tag_name| - tag = Tag.find_or_create_by_name(tag_name) - tagging = self.taggings.new - tagging.tag_id = tag.id + tag = Tag.find_or_create_by_name(tag_name) + tagging = self.taggings.new + tagging.tag_id = tag.id + end end end -end \ No newline at end of file diff --git a/app/models/author.rb b/app/models/author.rb index 19609d2..0eec46f 100644 --- a/app/models/author.rb +++ b/app/models/author.rb @@ -1,6 +1,5 @@ class Author < ActiveRecord::Base authenticates_with_sorcery! - #attr_accessible :crypted_password, :email, :salt, :username attr_accessible :username, :email, :password, :password_confirmation validates_confirmation_of :password, :message => "should match confirmation", :if => :password diff --git a/app/models/comment.rb b/app/models/comment.rb index 8854247..9b01929 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,4 @@ class Comment < ActiveRecord::Base - attr_accessible :author_name, :body belongs_to :article diff --git a/app/models/tag.rb b/app/models/tag.rb index 3b2512c..c7fc82c 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -4,6 +4,6 @@ class Tag < ActiveRecord::Base has_many :articles, :through => :taggings def to_s - name + name end end diff --git a/log/.gitkeep b/log/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb new file mode 100644 index 0000000..4007527 --- /dev/null +++ b/spec/models/article_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe Article do + describe "Associations" do + it { should have_many(:comments) } + it { should have_many(:taggings) } + it { should have_many(:tags) } + end +end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb new file mode 100644 index 0000000..4e5f548 --- /dev/null +++ b/spec/models/comment_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe Comment do + describe "Associations" do + it { should belong_to(:article) } + end +end diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb new file mode 100644 index 0000000..d627f57 --- /dev/null +++ b/spec/models/tag_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +describe Tag do + describe "Associations" do + it { should have_many(:taggings) } + it { should have_many(:articles) } + end +end diff --git a/spec/models/tagging_spec.rb b/spec/models/tagging_spec.rb new file mode 100644 index 0000000..5e40c33 --- /dev/null +++ b/spec/models/tagging_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +describe Tagging do + describe "Associations" do + it { should belong_to(:article) } + it { should belong_to(:tag) } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..0909127 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,38 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +require 'rspec/autorun' + +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} + +RSpec.configure do |config| + # ## Mock Framework + # + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr + + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # If true, the base class of anonymous controllers will be inferred + # automatically. This will be the default behavior in future versions of + # rspec-rails. + config.infer_base_class_for_anonymous_controllers = false + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = "random" +end