forked from charlotte-ruby/impressionist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added minitest tests, added 2 entities in order to handle compability…
… between rails versions
- Loading branch information
Showing
10 changed files
with
136 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
require "impressionist/engine" | ||
require 'impressionist/engine' | ||
|
||
require "impressionist/set_up_association" | ||
require 'impressionist/setup_association' | ||
|
||
require "impressionist/counter_cache" | ||
require 'impressionist/counter_cache' | ||
|
||
require "impressionist/update_counters" | ||
|
||
require "impressionist/rails_toggle" | ||
require 'impressionist/update_counters' | ||
|
||
require 'impressionist/rails_toggle' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Impressionist | ||
# Impressionist::SetupAssociation.new(entity).set | ||
class SetupAssociation | ||
def initialize(receiver) | ||
@receiver = receiver | ||
end | ||
|
||
# True or False | ||
# Note toggle returns false if rails >= 4 | ||
def include_attr_acc? | ||
toggle && make_accessible | ||
end | ||
|
||
def define_belongs_to | ||
receiver.belongs_to(:impressionable, :polymorphic => true) | ||
end | ||
|
||
# returns done if thruthy | ||
def set | ||
:done if (include_attr_acc? && define_belongs_to) | ||
end | ||
|
||
private | ||
attr_reader :receiver, :toggle | ||
|
||
def make_accessible | ||
receiver. | ||
attr_accessible(:impressionable_type, | ||
:impressionable_id, | ||
:controller_name, | ||
:request_hash, | ||
:session_hash, | ||
:action_name, | ||
:ip_address, | ||
:view_name, | ||
:referrer, | ||
:message, | ||
:user_id) | ||
end | ||
|
||
def toggle | ||
t = RailsToggle.new | ||
t.should_include? | ||
end | ||
end | ||
end | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,26 @@ | ||
# Responsability | ||
# Test whether rails version > 4 | ||
# includes attr_accessible if < 4 | ||
require 'test_helper.rb' | ||
require 'minitest_helper' | ||
require 'impressionist/rails_toggle' | ||
|
||
module Impressionist | ||
describe RailsToggle do | ||
|
||
describe "Rails 4" do | ||
before do | ||
@toggle = RailsToggle.new("4") | ||
end | ||
|
||
it "return current rails version" do | ||
@toggle.r_version.must_equal "4" | ||
end | ||
|
||
it "must not load attr_accessible" do | ||
@toggle.valid?.must_equal false | ||
end | ||
before { | ||
@toggle = RailsToggle.new | ||
} | ||
|
||
end | ||
|
||
describe "Rails 3.1.x" do | ||
describe "Rails 4" do | ||
|
||
before do | ||
@toggle = RailsToggle.new("3") | ||
# see your_minitest_path/lib/minitest/mock.rb | ||
it "must not include attr_accessible" do | ||
@toggle.stub :ask_rails, false do | ||
refute @toggle.should_include? | ||
end | ||
end | ||
|
||
it "includes" do | ||
@toggle.valid?.must_equal true | ||
end | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'minitest_helper' | ||
require 'impressionist/setup_association' | ||
|
||
module Impressionist | ||
describe SetupAssociation do | ||
|
||
let(:mock) { Minitest::Mock.new } | ||
let(:set_up) { SetupAssociation.new(mock) } | ||
|
||
before do | ||
# expects attr_accessible to return true | ||
# and pass 11 arguments | ||
mock. | ||
expect(:attr_accessible, true) do |args| | ||
args.size == 11 | ||
end | ||
|
||
end | ||
|
||
describe "attr_accessible" do | ||
|
||
it "includes" do | ||
set_up.stub :toggle, true do | ||
set_up.include_attr_acc?.must_equal true | ||
|
||
mock.verify | ||
end | ||
end | ||
|
||
end | ||
|
||
describe "belongs_to" do | ||
|
||
it "active_record" do | ||
mock.expect(:belongs_to, true, [Symbol, Hash]) | ||
set_up.define_belongs_to.must_equal true | ||
end | ||
|
||
end | ||
|
||
describe "#set" do | ||
|
||
it "sets an association" do | ||
def set_up.include_attr_acc?; true; end | ||
|
||
set_up.stub(:define_belongs_to, true) { | ||
set_up.set.must_equal :done | ||
} | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
end |