stale_fish 1.3.0.pre1 → 1.3.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0.pre1
1
+ 1.3.0.pre2
@@ -12,7 +12,6 @@ module StaleFish
12
12
  def setup(config_location=nil)
13
13
  self.configuration = config_location
14
14
  load
15
- register_fixtures
16
15
  block_requests
17
16
  end
18
17
 
@@ -21,14 +20,14 @@ module StaleFish
21
20
  end
22
21
 
23
22
  def configuration
24
- @configuration || if defined?(Rails)
25
- File.join(Rails.root, 'spec', 'stale_fish.yml')
26
- else
23
+ @configuration || #if defined?(Rails)
24
+ # File.join(Rails.root, 'spec', 'stale_fish.yml')
25
+ #else
27
26
  'stale_fish.yml'
28
- end
27
+ #end
29
28
  end
30
29
 
31
- def update_stale(options={})
30
+ def update_stale(options = :all)
32
31
  reset_fixtures = false
33
32
 
34
33
  allow_requests
@@ -38,17 +37,17 @@ module StaleFish
38
37
  reset_fixtures = true
39
38
  end
40
39
  end
41
- register_fixtures if reset_fixtures
40
+ drop_locks if reset_fixtures
42
41
  block_requests
43
42
  write
44
43
  end
45
44
 
46
- def update_stale!(options={})
45
+ def update_stale!(options = :all)
47
46
  allow_requests
48
47
  fixtures(options).each do |fixture|
49
48
  fixture.update!
50
49
  end
51
- register_fixtures
50
+ drop_locks
52
51
  block_requests
53
52
  write
54
53
  end
@@ -78,27 +77,28 @@ module StaleFish
78
77
  end
79
78
 
80
79
  def write
81
- updated_yaml = []
80
+ updated_yaml = "stale:\n"
82
81
  fixtures.each do |fixture|
83
82
  updated_yaml << fixture.to_yaml
84
83
  end
85
- updated_yaml = { :stale => updated_yaml }
86
- File.open(configuration, 'w') { |file| updated_yaml.to_yaml }
84
+ @full_yaml = updated_yaml
85
+ File.open(configuration, 'w') { |file| file.write(@full_yaml.to_s) }
87
86
  end
88
87
 
89
88
  def allow_requests
89
+ drop_locks
90
90
  FakeWeb.allow_net_connect = true
91
91
  end
92
92
 
93
93
  def block_requests
94
- FakeWeb.allow_net_connect = false
95
- end
96
-
97
- def register_fixtures
98
- FakeWeb.clean_registry
99
94
  fixtures.each do |fixture|
100
95
  fixture.register_lock!
101
96
  end
97
+ FakeWeb.allow_net_connect = false
98
+ end
99
+
100
+ def drop_locks
101
+ FakeWeb.clean_registry
102
102
  end
103
103
  end
104
104
  end
@@ -1,3 +1,5 @@
1
+ require 'activesupport'
2
+
1
3
  module StaleFish
2
4
  class Fixture
3
5
  attr_accessor :name, :file, :last_updated_at
@@ -10,7 +12,7 @@ module StaleFish
10
12
  end
11
13
 
12
14
  def is_stale?
13
- if last_updated_at.nil? || (last_updated_at + update_interval) < Time.now
15
+ if last_updated_at.nil? || (last_updated_at + eval(update_interval)) < DateTime.now
14
16
  return true
15
17
  else
16
18
  return false
@@ -28,12 +30,12 @@ module StaleFish
28
30
  write_response_to_file(response.body)
29
31
  end
30
32
 
31
- self.last_updated_at = Time.now
33
+ self.last_updated_at = DateTime.now
32
34
  end
33
35
 
34
36
  def register_lock!
35
37
  uri, type = build_uri, request_type.downcase.to_sym
36
- FakeWeb.register_uri(type, uri, :body => file)
38
+ FakeWeb.register_uri(type, uri, :body => 'hey dude')
37
39
 
38
40
  return FakeWeb.registered_uri?(type, uri)
39
41
  end
@@ -41,15 +43,23 @@ module StaleFish
41
43
  def to_yaml
42
44
  # update_interval.inspect trick is to prevent Fixnum being written
43
45
  yaml = <<-EOF
44
- #{name}:
45
- file: '#{file}'
46
- update_interval: #{update_interval.inspect.gsub(/ /, '.')}
47
- check_against: #{check_against}
48
- request_type: #{request_type}
49
- last_updated_at: #{last_updated_at}
46
+ #{name}:
47
+ file: '#{file}'
48
+ update_interval: #{update_interval.inspect.gsub(/ /, '.').gsub(/"/, '')}
49
+ check_against: #{check_against}
50
+ request_type: #{request_type}
51
+ last_updated_at: #{last_updated_at}
50
52
  EOF
51
53
  return yaml
52
54
  end
55
+
56
+ def last_updated_at
57
+ if @last_updated_at.nil? || @last_updated_at.is_a?(DateTime)
58
+ @last_updated_at
59
+ else
60
+ DateTime.parse(@last_updated_at.to_s)
61
+ end
62
+ end
53
63
 
54
64
  protected
55
65
 
@@ -62,7 +72,7 @@ EOF
62
72
  end
63
73
 
64
74
  def write_response_to_file(body)
65
- File.open(file, "w") { |file| file.write(body) }
75
+ File.open(File.join(File.dirname(StaleFish.configuration), file), "w") { |file| file.write(body) }
66
76
  end
67
77
  end
68
78
  end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
2
2
 
3
3
  describe StaleFish::Fixture do
4
4
  before do
5
- @time = Time.now
5
+ @time = DateTime.now
6
6
  @args = {
7
7
  :name => 'commits',
8
8
  :file => 'commit.json',
@@ -25,9 +25,9 @@ describe StaleFish::Fixture do
25
25
  context "#is_stale?" do
26
26
  before do
27
27
  @stale_fixture = StaleFish::Fixture.new(:last_updated_at => 1.week.ago,
28
- :update_interval => 1.day)
28
+ :update_interval => '1.day')
29
29
  @fresh_fixture = StaleFish::Fixture.new(:last_updated_at => 1.day.from_now,
30
- :update_interval => 1.day)
30
+ :update_interval => '1.day')
31
31
  end
32
32
 
33
33
  it "should return true when stale" do
@@ -54,7 +54,7 @@ describe StaleFish::Fixture do
54
54
  it "should update the fixture data" do
55
55
  @fixture.should_receive(:write_response_to_file).once.and_return(true)
56
56
  @fixture.update!
57
- @fixture.last_updated_at.should be_a(Time)
57
+ @fixture.last_updated_at.should be_a(DateTime)
58
58
  end
59
59
 
60
60
  it "should use Net::HTTP#get with a GET request_type"
@@ -76,19 +76,19 @@ describe StaleFish::Fixture do
76
76
  context "#to_yaml" do
77
77
  before do
78
78
  @fixture = StaleFish::Fixture.new(:name => 'google',
79
- :update_interval => 1.day,
79
+ :update_interval => '1.day',
80
80
  :request_type => 'GET',
81
81
  :check_against => 'http://google.com/index.html',
82
82
  :file => 'index.html',
83
83
  :last_updated_at => @time)
84
84
  @proper_yaml =
85
85
  <<-EOF
86
- google:
87
- file: 'index.html'
88
- update_interval: 1.day
89
- check_against: http://google.com/index.html
90
- request_type: GET
91
- last_updated_at: #{@time}
86
+ google:
87
+ file: 'index.html'
88
+ update_interval: 1.day
89
+ check_against: http://google.com/index.html
90
+ request_type: GET
91
+ last_updated_at: #{@time}
92
92
  EOF
93
93
  end
94
94
 
@@ -2,12 +2,12 @@ require File.join(File.dirname(__FILE__), *%w[.. spec_helper])
2
2
 
3
3
  describe StaleFish do
4
4
  before do
5
- @stale_fixture = StaleFish::Fixture.new(:last_updated_at => 1.week.ago,
6
- :update_interval => 1.day,
5
+ @stale_fixture = StaleFish::Fixture.new(:last_updated_at => 1.week.ago.to_datetime,
6
+ :update_interval => '1.day',
7
7
  :request_type => 'GET',
8
8
  :check_against => 'http://google.com/index.html')
9
- @fresh_fixture = StaleFish::Fixture.new(:last_updated_at => 1.day.from_now,
10
- :update_interval => 1.day,
9
+ @fresh_fixture = StaleFish::Fixture.new(:last_updated_at => 1.day.from_now.to_datetime,
10
+ :update_interval => '1.day',
11
11
  :request_type => 'GET',
12
12
  :check_against => 'http://google.com/index.html')
13
13
  end
@@ -15,7 +15,6 @@ describe StaleFish do
15
15
  context ".setup" do
16
16
  it "should call appropriate functions" do
17
17
  StaleFish.should_receive(:load)
18
- StaleFish.should_receive(:register_fixtures)
19
18
  StaleFish.should_receive(:block_requests)
20
19
  StaleFish.setup
21
20
  end
@@ -134,8 +133,4 @@ describe StaleFish do
134
133
  StaleFish.send(:block_requests).should == false
135
134
  end
136
135
  end
137
-
138
- context ".register_fixtures" do
139
-
140
- end
141
136
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{stale_fish}
8
- s.version = "1.3.0.pre1"
8
+ s.version = "1.3.0.pre2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Smestad"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stale_fish
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.pre1
4
+ version: 1.3.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Smestad