diff --git a/.travis.yml b/.travis.yml index 176ae7f..8604013 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: ruby rvm: - - 1.9.3 - - 2.0.0 - 2.2.2 + - 2.3.7 + - 2.4.4 + - 2.5.1 gemfile: - - gemfiles/4.0.gemfile - - gemfiles/4.1.gemfile - - gemfiles/4.2.gemfile + - gemfiles/5.0.gemfile + - gemfiles/5.1.gemfile + - gemfiles/5.2.gemfile script: "bundle exec rake clean test" diff --git a/Gemfile.lock b/Gemfile.lock index b28788d..f151190 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,65 +1,69 @@ PATH remote: . specs: - has_draft (1.3.0) - activerecord (>= 3.0.0) - activesupport (>= 3.0.0) + has_draft (2.0.0) + activerecord (>= 5.0.0) + activesupport (>= 5.0.0) GEM remote: https://rubygems.org/ specs: - activemodel (4.2.3) - activesupport (= 4.2.3) - builder (~> 3.1) - activerecord (4.2.3) - activemodel (= 4.2.3) - activesupport (= 4.2.3) - arel (~> 6.0) - activesupport (4.2.3) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) + activemodel (5.2.1) + activesupport (= 5.2.1) + activerecord (5.2.1) + activemodel (= 5.2.1) + activesupport (= 5.2.1) + arel (>= 9.0) + activesupport (5.2.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - appraisal (2.0.2) + appraisal (2.2.0) bundler rake thor (>= 0.14.0) - arel (6.0.0) - builder (3.2.2) - diff-lcs (1.2.5) - factory_girl (1.3.3) - faker (0.9.5) - i18n (~> 0.4) - i18n (0.7.0) - json (1.8.3) - minitest (5.7.0) - rake (10.4.2) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.99.4) - sqlite3 (1.3.10) - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (1.2.2) + arel (9.0.0) + concurrent-ruby (1.0.5) + diff-lcs (1.3) + factory_bot (4.11.0) + activesupport (>= 3.0.0) + faker (1.9.1) + i18n (>= 0.7) + i18n (1.1.0) + concurrent-ruby (~> 1.0) + minitest (5.11.3) + rake (12.3.1) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + sqlite3 (1.3.13) + thor (0.20.0) + thread_safe (0.3.6) + tzinfo (1.2.5) thread_safe (~> 0.1) PLATFORMS ruby DEPENDENCIES - appraisal (~> 2.0.2) - factory_girl (~> 1.3.1) - faker (~> 0.9.1) + appraisal (~> 2.2.0) + factory_bot (~> 4.11) + faker (~> 1.9.1) has_draft! rake - rspec (~> 2.0) - sqlite3 (~> 1.3.4) + rspec (~> 3.8) + sqlite3 (~> 1.3.13) BUNDLED WITH - 1.10.4 + 1.16.3 diff --git a/gemfiles/4.0.gemfile.lock b/gemfiles/4.0.gemfile.lock deleted file mode 100644 index 1d50208..0000000 --- a/gemfiles/4.0.gemfile.lock +++ /dev/null @@ -1,102 +0,0 @@ -PATH - remote: ../ - specs: - has_draft (1.3.0) - activerecord (>= 3.0.0) - activesupport (>= 3.0.0) - -GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.0.13) - actionpack (= 4.0.13) - mail (~> 2.5, >= 2.5.4) - actionpack (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - activemodel (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - activerecord (4.0.13) - activemodel (= 4.0.13) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.13) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) - activesupport (4.0.13) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - appraisal (2.0.2) - bundler - rake - thor (>= 0.14.0) - arel (4.0.2) - builder (3.1.4) - diff-lcs (1.2.5) - erubis (2.7.0) - factory_girl (1.3.3) - faker (0.9.5) - i18n (~> 0.4) - i18n (0.7.0) - mail (2.6.3) - mime-types (>= 1.16, < 3) - mime-types (2.6.1) - minitest (4.7.5) - multi_json (1.11.2) - rack (1.5.5) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.0.13) - actionmailer (= 4.0.13) - actionpack (= 4.0.13) - activerecord (= 4.0.13) - activesupport (= 4.0.13) - bundler (>= 1.3.0, < 2.0) - railties (= 4.0.13) - sprockets-rails (~> 2.0) - railties (4.0.13) - actionpack (= 4.0.13) - activesupport (= 4.0.13) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.4.2) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.99.4) - sprockets (3.2.0) - rack (~> 1.0) - sprockets-rails (2.3.2) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) - sqlite3 (1.3.10) - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (0.3.44) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (~> 2.0.2) - factory_girl (~> 1.3.1) - faker (~> 0.9.1) - has_draft! - rails (~> 4.0.0) - rake - rspec (~> 2.0) - sqlite3 (~> 1.3.4) - -BUNDLED WITH - 1.10.4 diff --git a/gemfiles/4.1.gemfile.lock b/gemfiles/4.1.gemfile.lock deleted file mode 100644 index a6aba33..0000000 --- a/gemfiles/4.1.gemfile.lock +++ /dev/null @@ -1,107 +0,0 @@ -PATH - remote: ../ - specs: - has_draft (1.3.0) - activerecord (>= 3.0.0) - activesupport (>= 3.0.0) - -GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.1.12) - actionpack (= 4.1.12) - actionview (= 4.1.12) - mail (~> 2.5, >= 2.5.4) - actionpack (4.1.12) - actionview (= 4.1.12) - activesupport (= 4.1.12) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - actionview (4.1.12) - activesupport (= 4.1.12) - builder (~> 3.1) - erubis (~> 2.7.0) - activemodel (4.1.12) - activesupport (= 4.1.12) - builder (~> 3.1) - activerecord (4.1.12) - activemodel (= 4.1.12) - activesupport (= 4.1.12) - arel (~> 5.0.0) - activesupport (4.1.12) - i18n (~> 0.6, >= 0.6.9) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.1) - tzinfo (~> 1.1) - appraisal (2.0.2) - bundler - rake - thor (>= 0.14.0) - arel (5.0.1.20140414130214) - builder (3.2.2) - diff-lcs (1.2.5) - erubis (2.7.0) - factory_girl (1.3.3) - faker (0.9.5) - i18n (~> 0.4) - i18n (0.7.0) - json (1.8.3) - mail (2.6.3) - mime-types (>= 1.16, < 3) - mime-types (2.6.1) - minitest (5.7.0) - rack (1.5.5) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.1.12) - actionmailer (= 4.1.12) - actionpack (= 4.1.12) - actionview (= 4.1.12) - activemodel (= 4.1.12) - activerecord (= 4.1.12) - activesupport (= 4.1.12) - bundler (>= 1.3.0, < 2.0) - railties (= 4.1.12) - sprockets-rails (~> 2.0) - railties (4.1.12) - actionpack (= 4.1.12) - activesupport (= 4.1.12) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.4.2) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.99.4) - sprockets (3.2.0) - rack (~> 1.0) - sprockets-rails (2.3.2) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) - sqlite3 (1.3.10) - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (~> 2.0.2) - factory_girl (~> 1.3.1) - faker (~> 0.9.1) - has_draft! - rails (~> 4.1.12) - rake - rspec (~> 2.0) - sqlite3 (~> 1.3.4) - -BUNDLED WITH - 1.10.4 diff --git a/gemfiles/4.2.gemfile.lock b/gemfiles/4.2.gemfile.lock deleted file mode 100644 index 79ef0d7..0000000 --- a/gemfiles/4.2.gemfile.lock +++ /dev/null @@ -1,132 +0,0 @@ -PATH - remote: ../ - specs: - has_draft (1.3.0) - activerecord (>= 3.0.0) - activesupport (>= 3.0.0) - -GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.2.3) - actionpack (= 4.2.3) - actionview (= 4.2.3) - activejob (= 4.2.3) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.3) - actionview (= 4.2.3) - activesupport (= 4.2.3) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.3) - activesupport (= 4.2.3) - builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.3) - activesupport (= 4.2.3) - globalid (>= 0.3.0) - activemodel (4.2.3) - activesupport (= 4.2.3) - builder (~> 3.1) - activerecord (4.2.3) - activemodel (= 4.2.3) - activesupport (= 4.2.3) - arel (~> 6.0) - activesupport (4.2.3) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - appraisal (2.0.2) - bundler - rake - thor (>= 0.14.0) - arel (6.0.0) - builder (3.2.2) - diff-lcs (1.2.5) - erubis (2.7.0) - factory_girl (1.3.3) - faker (0.9.5) - i18n (~> 0.4) - globalid (0.3.5) - activesupport (>= 4.1.0) - i18n (0.7.0) - json (1.8.3) - loofah (2.0.2) - nokogiri (>= 1.5.9) - mail (2.6.3) - mime-types (>= 1.16, < 3) - mime-types (2.6.1) - mini_portile (0.6.2) - minitest (5.7.0) - nokogiri (1.6.6.2) - mini_portile (~> 0.6.0) - rack (1.6.4) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.2.3) - actionmailer (= 4.2.3) - actionpack (= 4.2.3) - actionview (= 4.2.3) - activejob (= 4.2.3) - activemodel (= 4.2.3) - activerecord (= 4.2.3) - activesupport (= 4.2.3) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.3) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.6) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.2) - loofah (~> 2.0) - railties (4.2.3) - actionpack (= 4.2.3) - activesupport (= 4.2.3) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.4.2) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.99.4) - sprockets (3.2.0) - rack (~> 1.0) - sprockets-rails (2.3.2) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) - sqlite3 (1.3.10) - thor (0.19.1) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (~> 2.0.2) - factory_girl (~> 1.3.1) - faker (~> 0.9.1) - has_draft! - rails (~> 4.2.3) - rake - rspec (~> 2.0) - sqlite3 (~> 1.3.4) - -BUNDLED WITH - 1.10.4 diff --git a/gemfiles/4.0.gemfile b/gemfiles/5.0.gemfile similarity index 79% rename from gemfiles/4.0.gemfile rename to gemfiles/5.0.gemfile index c6d0a1f..123ad55 100644 --- a/gemfiles/4.0.gemfile +++ b/gemfiles/5.0.gemfile @@ -2,6 +2,6 @@ source "https://rubygems.org" -gem "rails", "~> 4.0.0" +gem "rails", "~> 5.0.0" gemspec :path => "../" diff --git a/gemfiles/4.2.gemfile b/gemfiles/5.1.gemfile similarity index 79% rename from gemfiles/4.2.gemfile rename to gemfiles/5.1.gemfile index a8b7aab..20a05ff 100644 --- a/gemfiles/4.2.gemfile +++ b/gemfiles/5.1.gemfile @@ -2,6 +2,6 @@ source "https://rubygems.org" -gem "rails", "~> 4.2.3" +gem "rails", "~> 5.1.0" gemspec :path => "../" diff --git a/gemfiles/4.1.gemfile b/gemfiles/5.2.gemfile similarity index 79% rename from gemfiles/4.1.gemfile rename to gemfiles/5.2.gemfile index 2504547..0c9d569 100644 --- a/gemfiles/4.1.gemfile +++ b/gemfiles/5.2.gemfile @@ -2,6 +2,6 @@ source "https://rubygems.org" -gem "rails", "~> 4.1.12" +gem "rails", "~> 5.2.0" gemspec :path => "../" diff --git a/has_draft.gemspec b/has_draft.gemspec index f0cced0..b6c342f 100644 --- a/has_draft.gemspec +++ b/has_draft.gemspec @@ -11,19 +11,19 @@ Gem::Specification.new do |s| s.summary = "Attached draft model to your ActiveRecord models." s.description = "Allows for your ActiveRecord models to have drafts which are stored in a separate duplicate table." s.license = "MIT" - + s.files = Dir["{lib,spec}/**/*", "[A-Z]*", "init.rb"] s.require_path = "lib" - + s.rubyforge_project = s.name s.required_rubygems_version = ">= 1.3.4" - - s.add_dependency("activesupport", [">= 3.0.0"]) - s.add_dependency("activerecord", [">= 3.0.0"]) - s.add_development_dependency("rspec", ["~> 2.0"]) - s.add_development_dependency("factory_girl", ["~> 1.3.1"]) - s.add_development_dependency("faker", ["~> 0.9.1"]) - s.add_development_dependency("sqlite3", ["~> 1.3.4"]) - s.add_development_dependency("appraisal", ["~> 2.0.2"]) + + s.add_dependency("activesupport", [">= 5.0.0"]) + s.add_dependency("activerecord", [">= 5.0.0"]) + s.add_development_dependency("rspec", ["~> 3.8"]) + s.add_development_dependency("factory_bot", ["~> 4.11"]) + s.add_development_dependency("faker", ["~> 1.9.1"]) + s.add_development_dependency("sqlite3", ["~> 1.3.13"]) + s.add_development_dependency("appraisal", ["~> 2.2.0"]) s.add_development_dependency "rake" end diff --git a/lib/has_draft.rb b/lib/has_draft.rb index fb186be..99c0f20 100644 --- a/lib/has_draft.rb +++ b/lib/has_draft.rb @@ -2,24 +2,24 @@ module HasDraft def self.included(base) base.extend ClassMethods end - + module ClassMethods def has_draft(options = {}, &block) return if self.included_modules.include?(HasDraft::InstanceMethods) include HasDraft::InstanceMethods - + cattr_accessor :draft_class_name, :draft_foreign_key, :draft_table_name, :draft_columns - + self.draft_class_name = options[:class_name] || 'Draft' self.draft_foreign_key = options[:foreign_key] || self.to_s.foreign_key self.draft_table_name = options[:table_name] || "#{table_name_prefix}#{base_class.name.demodulize.underscore}_drafts#{table_name_suffix}" - + # Create Relationship to Draft Copy class_eval do has_one :draft, :class_name => "#{self.to_s}::#{draft_class_name}", :foreign_key => draft_foreign_key, :dependent => :destroy - + scope :with_draft, lambda { includes(:draft).where("#{draft_table_name}.id IS NOT NULL").references(draft_table_name) } scope :without_draft, lambda { includes(:draft).where("#{draft_table_name}.id IS NULL").references(draft_table_name) } end @@ -29,7 +29,7 @@ def has_draft(options = {}, &block) # Dynamically Create Model::Draft Class const_set(draft_class_name, Class.new(options[:extends])) - + draft_class.cattr_accessor :original_class draft_class.original_class = self draft_class.table_name = draft_table_name @@ -39,85 +39,85 @@ def has_draft(options = {}, &block) # Draft Parent Association draft_class.belongs_to options[:belongs_to], :class_name => "::#{self.to_s}", :foreign_key => draft_foreign_key - + # Block extension draft_class.class_eval(&block) if block_given? - + # Finally setup which columns to draft self.draft_columns = draft_class.new.attributes.keys - [draft_class.primary_key, draft_foreign_key, 'created_at', 'updated_at', inheritance_column] end - + def draft_class const_get(draft_class_name) end end - + module InstanceMethods def has_draft? !self.draft.nil? end - + def save_to_draft(perform_validation = true) return false if perform_validation and !self.valid? - + instantiate_draft! unless has_draft? copy_attributes_to_draft - + self.draft.save(perform_validation) self.reload end - + def instantiate_draft self.build_draft - + copy_attributes_to_draft before_instantiate_draft - + self.draft.tap(&:save) end - + def instantiate_draft! instantiate_draft do |draft| draft.save unless self.new_record? end end - + def copy_attributes_to_draft self.class.draft_columns.each do |attribute| self.draft.send("#{attribute}=", send(attribute)) end self end - + def copy_attributes_from_draft self.class.draft_columns.each do |attribute| self.send("#{attribute}=", self.draft.send(attribute)) end self end - + def before_instantiate_draft end - + def replace_with_draft! copy_attributes_from_draft - + before_replace_with_draft - + self.save unless self.new_record? self end - + def before_replace_with_draft end - + def destroy_draft! before_destroy_draft - + self.draft.destroy if self.draft - self.draft(true) + self.reload end - + def before_destroy_draft end end diff --git a/lib/has_draft/version.rb b/lib/has_draft/version.rb index 4676df4..0a726da 100644 --- a/lib/has_draft/version.rb +++ b/lib/has_draft/version.rb @@ -1,3 +1,3 @@ module HasDraft - VERSION = "1.3.0" + VERSION = "2.0.0" end diff --git a/spec/factories/article.rb b/spec/factories/article.rb index 855dd34..d331484 100644 --- a/spec/factories/article.rb +++ b/spec/factories/article.rb @@ -1,20 +1,22 @@ -require "factory_girl" +require "factory_bot" -Factory.define(:article) do |f| - f.title { Faker::Lorem.sentence } - f.summary { Faker::Lorem.paragraphs.first } - f.body { Faker::Lorem.paragraphs.join("\n\n") } - f.post_date { 1.day.ago.to_date } -end +FactoryBot.define do + factory(:article) do |f| + f.title { Faker::Lorem.sentence } + f.summary { Faker::Lorem.paragraphs.first } + f.body { Faker::Lorem.paragraphs.join("\n\n") } + f.post_date { 1.day.ago.to_date } + end -Factory.define(:article_draft, :class => Article::Draft) do |f| - f.association(:article) - f.title { Faker::Lorem.sentence } - f.summary { Faker::Lorem.paragraphs.first } - f.body { Faker::Lorem.paragraphs.join("\n\n") } - f.post_date { 1.day.ago.to_date } -end + factory(:article_draft, :class => Article::Draft) do |f| + f.association(:article) + f.title { Faker::Lorem.sentence } + f.summary { Faker::Lorem.paragraphs.first } + f.body { Faker::Lorem.paragraphs.join("\n\n") } + f.post_date { 1.day.ago.to_date } + end -Factory.define(:article_with_draft, :parent => :article) do |f| - f.association(:draft, :factory => :article_draft) -end + factory(:article_with_draft, :parent => :article) do |f| + f.association(:draft, :factory => :article_draft) + end +end \ No newline at end of file diff --git a/spec/has_draft_spec.rb b/spec/has_draft_spec.rb index 94fccc7..be10be0 100644 --- a/spec/has_draft_spec.rb +++ b/spec/has_draft_spec.rb @@ -7,79 +7,79 @@ context "Model with has_draft" do it "should expose #draft_class_name as Draft" do - Article.draft_class_name.should == "Draft" + expect(Article.draft_class_name).to eql("Draft") end - + it "should expose #draft_class as Article::Draft" do - Article.draft_class.should == Article::Draft + expect(Article.draft_class).to eql(Article::Draft) end - + it "should default #draft_foreign_key as article_id" do - Article.draft_foreign_key.should == "article_id" + expect(Article.draft_foreign_key).to eql("article_id") end - + it "should default #draft_table_name as article_drafts" do - Article.draft_table_name.should == "article_drafts" + expect(Article.draft_table_name).to eql("article_drafts") end - + it "should expose #with_draft and #without_draft scopes" do expect { Article.with_draft.to_a }.to_not raise_error expect { Article.without_draft.to_a }.to_not raise_error end - + describe "Draft Model" do it "should be defined under the Article namespace" do - Article.constants.map(&:to_s).should include('Draft') + expect(Article.constants.map(&:to_s)).to include('Draft') end - + it "should expose #original_class as Article" do - Article::Draft.original_class.should == Article + expect(Article::Draft.original_class).to eql(Article) end end end - + context "an article" do - before { @article = Factory.create(:article) } - + before { @article = FactoryBot.create(:article) } + context "when instantiating a new draft" do before { @article.instantiate_draft! } - + it "should create draft" do - @article.draft.should_not be_nil - @article.draft.should_not be_new_record + expect(@article.draft).to_not be_nil + expect(@article.draft).to_not be_new_record end - + it "should copy draft fields" do Article.draft_columns.each do |column| - @article.send(column).should == @article.draft.send(column) + expect(@article.send(column)).to eql(@article.draft.send(column)) end end end - + context "when destroying an existing draft" do before do - @article = Factory.create(:article_with_draft) + @article = FactoryBot.create(:article_with_draft) @article.destroy_draft! end - + it "should associated draft" do - @article.draft.should be_nil + expect(@article.draft).to be_nil end end - + context "when replacing with draft" do before do - @article = Factory.create(:article_with_draft) + @article = FactoryBot.create(:article_with_draft) @article.replace_with_draft! end - + it "should still have draft" do - @article.draft.should_not be_nil + expect(@article.draft).to_not be_nil end - + it "should now have the same field values as draft" do Article.draft_columns.each do |column| - @article.send(column).should == @article.draft.send(column) + expect(@article.send(column)).to eql(@article.draft.send(column)) end end end @@ -88,23 +88,23 @@ context "Draft class extends" do it "ActiveRecord::Base when no options are passed" do - Article::Draft.superclass.should == ActiveRecord::Base + expect(Article::Draft.superclass).to eql(ActiveRecord::Base) end it "the class passed in with the :extends option" do - BlogPost::Draft.superclass.should == Post + expect(BlogPost::Draft.superclass).to eql(Post) end end context "Draft class belongs to" do it "self when :belongs_to is not specified" do - Article::Draft.reflect_on_association(:article).macro.should == :belongs_to + expect(Article::Draft.reflect_on_association(:article).macro).to eql(:belongs_to) end it "the model passed in with the :belongs_to option" do - BlogPost::Draft.reflect_on_association(:post).macro.should == :belongs_to + expect(BlogPost::Draft.reflect_on_association(:post).macro).to eql(:belongs_to) end end - + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cae8b3a..4c10ee4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require "rubygems" require "rspec" -require "factory_girl" +require "factory_bot" require "faker" require "active_record" require "active_support"