zelda 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.1.0 (Aug 11, 2011)
2
+
3
+ Bugfixes:
4
+
5
+ - Return nil for attributes that exist, but have nil value
6
+ - Made the base class slimmer
7
+ - Shared examples for the base class are now less brittle
8
+
9
+
1
10
  ## 1.0.0 (Aug 11, 2011)
2
11
 
3
12
  Features:
@@ -52,4 +61,4 @@ Features:
52
61
 
53
62
  Features:
54
63
 
55
- - Initial version
64
+ - Initial version
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zelda (0.1.0)
4
+ zelda (1.0.0)
5
5
  httparty
6
6
 
7
7
  GEM
data/lib/zelda/base.rb CHANGED
@@ -1,21 +1,23 @@
1
1
  module Zelda
2
2
  # Abstract base class to provide common functionality of Zelda importer classes.
3
- # including method_missing magic to turn an @attrs hash into getters.
3
+ # including method_missing magic to turn an @attributes hash into getters.
4
4
  class Base
5
- def initialize(attrs={})
6
- @attrs = attrs
5
+ def initialize(attributes={})
6
+ @attributes = {}
7
+
8
+ attributes.each do |key, value|
9
+ @attributes[key.to_sym] = value
10
+ end
7
11
  end
8
-
9
- def attributes
10
- @attrs
11
- end
12
+
13
+ attr_reader :attributes
12
14
 
13
15
  # Try both string keys and symbol keys in that order.
14
16
  def method_missing(method, *args, &block)
15
- if @attrs[method.to_s]
16
- return @attrs[method.to_s]
17
- elsif @attrs[method]
18
- return @attrs[method]
17
+ if @attributes[method]
18
+ return @attributes[method]
19
+ elsif @attributes.key?(method)
20
+ return nil
19
21
  else
20
22
  super(method, *args, &block)
21
23
  end
data/lib/zelda/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Zelda
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/zelda/zender.rb CHANGED
@@ -12,11 +12,11 @@ module Zelda
12
12
  end
13
13
 
14
14
  def name
15
- @attrs["zender"]["name"]
15
+ attributes[:zender]["name"]
16
16
  end
17
17
 
18
18
  def code
19
- @attrs["zender"]["code"]
19
+ attributes[:zender]["code"]
20
20
  end
21
21
 
22
22
  # Return all Series for this Zender.
@@ -1,9 +1,13 @@
1
1
  shared_examples_for "a zelda base model" do
2
2
  it "should respond to the attributes set in the constructor" do
3
- @model.foo.should == 'bar'
3
+ described_class.new(:foo => 'bar').foo.should eq('bar')
4
+ end
5
+
6
+ it "should return nil for an attribute set to nil" do
7
+ described_class.new(:foo => nil).foo.should be_nil
4
8
  end
5
9
 
6
10
  it "should not respond to attributes not set in the constructor" do
7
- lambda { @model.no_not_here_nope }.should raise_error(NoMethodError)
11
+ lambda { subject.no_not_here_nope }.should raise_error(NoMethodError)
8
12
  end
9
13
  end
@@ -1,10 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Zelda::Aflevering do
4
- before do
5
- @model = Zelda::Aflevering.new(:foo => "bar")
6
- end
7
-
4
+
8
5
  it_should_behave_like 'a zelda base model'
9
6
 
10
7
  it "should accept attributes when being initialized" do
@@ -1,10 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Zelda::Omroep do
4
- before do
5
- @model = Zelda::Omroep.new(:foo => "bar")
6
- end
7
-
4
+
8
5
  it_should_behave_like 'a zelda base model'
9
6
 
10
7
  describe "when retrieving a list of omroepen" do
@@ -1,28 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Zelda::Serie do
4
+ it_should_behave_like 'a zelda base model'
5
+
4
6
  describe "current series" do
5
7
  it "calls Zelda with the correct url" do
6
- Zelda::Request.should_receive(:get).with("current_series").and_return({'series' => ['serie']})
8
+ Zelda::Request.should_receive(:get).with("current_series").and_return({'series' => [{'titel' => 'Titeuf'}]})
7
9
  Zelda::Serie.stub(:new).and_return('serie')
8
10
  Zelda::Serie.current.should == ['serie']
9
11
  end
10
12
 
11
13
  it "should return an array of series" do
12
- Zelda::Request.should_receive(:get).with("series").and_return({ 'series' => ['serie'] })
13
- Zelda::Serie.all.first.should be_a(Zelda::Serie)
14
+ Zelda::Request.should_receive(:get).with("current_series").and_return({ 'series' => [{'titel' => 'Titeuf'}] })
15
+ Zelda::Serie.current.first.should be_a(Zelda::Serie)
14
16
  end
15
17
  end
16
18
 
17
19
  describe "when retrieving a list of series" do
18
20
  it "should call Zelda with the correct url" do
19
- Zelda::Request.should_receive(:get).with("series").and_return({ 'series' => ['serie'] })
21
+ Zelda::Request.should_receive(:get).with("series").and_return({ 'series' => [{'titel' => 'Titeuf'}] })
20
22
  Zelda::Serie.stub!(:new).and_return 'serie'
21
23
  Zelda::Serie.all.should == ['serie']
22
24
  end
23
25
 
24
26
  it "should return an array of series" do
25
- Zelda::Request.should_receive(:get).with("series").and_return({ 'series' => ['serie'] })
27
+ Zelda::Request.should_receive(:get).with("series").and_return({ 'series' => [{'titel' => 'Titeuf'}] })
26
28
  Zelda::Serie.all.first.should be_a(Zelda::Serie)
27
29
  end
28
30
  end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Zelda::Zender do
4
+ it_should_behave_like 'a zelda base model'
5
+
4
6
  describe "when retrieving a list of zenders" do
5
7
  it "should call Zelda with the correct url" do
6
8
  Zelda::Request.should_receive(:get).with("zenders")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: zelda
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joost Baaij