mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
fixed registered_attributes inheritance
This commit is contained in:
parent
518762f7ae
commit
7f32b239a3
5 changed files with 47 additions and 5 deletions
|
@ -5,14 +5,26 @@ module FbGraph2
|
|||
included do
|
||||
extend ClassMethods
|
||||
attr_accessor :raw_attributes
|
||||
cattr_accessor :registered_attributes
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def register_attributes(attributes)
|
||||
self.registered_attributes = attributes
|
||||
@registered_attributes ||= {}
|
||||
attributes.each do |type, keys|
|
||||
@registered_attributes[type] ||= []
|
||||
@registered_attributes[type] += keys
|
||||
end
|
||||
send :attr_accessor, *attributes.values.flatten
|
||||
end
|
||||
|
||||
def registered_attributes
|
||||
@registered_attributes
|
||||
end
|
||||
|
||||
def inherited(child)
|
||||
super
|
||||
child.register_attributes registered_attributes
|
||||
end
|
||||
end
|
||||
|
||||
def assign(attributes)
|
||||
|
|
|
@ -14,6 +14,8 @@ module FbGraph2
|
|||
register_attributes(
|
||||
raw: [:app_store_id]
|
||||
)
|
||||
class IPhone < IOS; end
|
||||
class IPad < IOS; end
|
||||
end
|
||||
|
||||
class Android < Native
|
||||
|
@ -24,7 +26,7 @@ module FbGraph2
|
|||
|
||||
class WindowsPhone < Native
|
||||
register_attributes(
|
||||
raw: [:app_name]
|
||||
raw: [:app_id]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -60,7 +60,6 @@ describe FbGraph2::Node do
|
|||
subject { klass }
|
||||
it { should_not respond_to :register_attributes }
|
||||
it { should_not respond_to :registered_attributes }
|
||||
it { should_not respond_to :registered_attributes= }
|
||||
end
|
||||
|
||||
context 'instance' do
|
||||
|
|
|
@ -13,7 +13,6 @@ describe FbGraph2::NodeSubClass do
|
|||
subject { klass }
|
||||
it { should respond_to :register_attributes }
|
||||
it { should respond_to :registered_attributes }
|
||||
it { should respond_to :registered_attributes= }
|
||||
end
|
||||
|
||||
context 'instance' do
|
||||
|
|
30
spec/fb_graph2/struct/app_link_spec.rb
Normal file
30
spec/fb_graph2/struct/app_link_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe FbGraph2::Struct::AppLink do
|
||||
subject { described_class }
|
||||
its(:registered_attributes) { should == {raw: [:url]} }
|
||||
|
||||
describe FbGraph2::Struct::AppLink::Native do
|
||||
its(:registered_attributes) { should == {raw: [:url, :app_name]} }
|
||||
end
|
||||
|
||||
describe FbGraph2::Struct::AppLink::Native::IOS do
|
||||
its(:registered_attributes) { should == {raw: [:url, :app_name, :app_store_id]} }
|
||||
|
||||
describe FbGraph2::Struct::AppLink::Native::IOS::IPhone do
|
||||
its(:registered_attributes) { should == {raw: [:url, :app_name, :app_store_id]} }
|
||||
end
|
||||
end
|
||||
|
||||
describe FbGraph2::Struct::AppLink::Native::Android do
|
||||
its(:registered_attributes) { should == {raw: [:url, :app_name, :class, :package]} }
|
||||
end
|
||||
|
||||
describe FbGraph2::Struct::AppLink::Native::WindowsPhone do
|
||||
its(:registered_attributes) { should == {raw: [:url, :app_name, :app_id]} }
|
||||
end
|
||||
|
||||
describe FbGraph2::Struct::AppLink::Web do
|
||||
its(:registered_attributes) { should == {raw: [:url, :should_fallback]} }
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue