kickscraper icon indicating copy to clipboard operation
kickscraper copied to clipboard

Flesh out handling of Updates

Open ghost opened this issue 12 years ago • 15 comments

  • Provide explicit attribute accessors for the Update type
  • Handle "more updates" in a manner consistent with the existing "more projects" functionality
  • Add tests to the client spec and a new update spec

ghost avatar Dec 19 '13 05:12 ghost

These two commits address different but related issues, so I can squash them and open a new pull request if that is preferable.

ghost avatar Dec 19 '13 05:12 ghost

Thanks for the contribution, can you also add some tests for these? I'd prefer to see less in-code comments and more tests which describe the desired behaviour and handling of edge cases.

Any comments from @markolson or @benrugg ?

jamlen avatar Dec 19 '13 11:12 jamlen

Sure thing, I'll work on getting some tests together.

ghost avatar Dec 19 '13 15:12 ghost

My one comment isn't particularly relevant to this PR, but the pattern

def THING
    reload! unless @raw['THING']
    @raw['THING']
end

is repeated a lot, and we can probably DRYing that up easily :)

markolson avatar Dec 19 '13 15:12 markolson

Hey, @ajkerrigan, thanks for adding this functionality. It's great to have more contributions to kickscraper!

benrugg avatar Dec 19 '13 19:12 benrugg

I've added some tests, and had to tweak a couple things along the way to get them all to pass. I guess that's how it's supposed to work! I added small comments in one or two places where the necessary changes were not obvious (at least to me).

I'm pretty green when it comes to Ruby, RSpec and open source contributions in general - so don't be shy if these changes don't jive with the conventions you've established.

ghost avatar Dec 24 '13 05:12 ghost

Sorry nobody has checked this out yet. I'll try to get to it sometime soon. Or if anyone else has a chance, go for it!

benrugg avatar Dec 28 '13 06:12 benrugg

Hey @ajkerrigan, thanks again for adding this functionality. It looks great to me. I made one note on a specific test if you want to check that out...

benrugg avatar Dec 30 '13 20:12 benrugg

Ah yes I see what you're saying there. It may be that I'm misunderstanding something about how the subject block works. I actually modeled that test after an existing project test, because I was trying to do essentially the same thing:

context "loads more projects after a successful search" do
subject do 
  client.recently_launched_projects
  client.more_projects_available?.should be_true
  client.load_more_projects 
end

it_returns "a collection", Kickscraper::Project
end

It looked to me like the it_returns piece was referring to the last value in the subject block, which is the array returned by load_more_projects. In my case, I figured the effective subject would be the array returned by load_more_updates. Even though it seems to pass, it definitely feels dirty and looks a bit awkward. Does this seem like a reasonable replacement?

  context "loads more updates when available" do
    before { client.find_project(TEST_PROJECT_ID) }

    describe "more updates are available" do
      subject { client }
      its(:more_updates_available?) { should be_true }
    end
    describe "more updates load properly" do
      subject { client.load_more_updates }
      it_returns "a collection", Kickscraper::Update
    end
  end

ghost avatar Dec 30 '13 22:12 ghost

Ah yeah, gotcha. You know what... I was talking about the test "throws an error when accessing updates without a valid project loaded". That one seemed weird to me, because it seemed like the way the code is written, it is pulling in a valid project for the subject, rather than an invalid one.

But, I think you're right about the new way of writing the other two tests. That looks more semantic. Either way I think is probably fine. (But I'm not a guru at writing tests!)

benrugg avatar Dec 31 '13 00:12 benrugg

CAVEAT: I've not looked at this since June and I'm currently working in NodeJS so my memory is a bit fuzzy :)

Just a thought but why are these update methods on client.rb and not on project? After all the updates are only related to a given project. It seems from your commit that load_more_updates method is only used from the tests.

This would then lead to:

  context "loads more updates when available" do
    let(:project) { client.find_project(TEST_PROJECT_ID) }

    describe "more updates are available" do
      subject { project }
      its(:more_updates_available?) { should be_true }
    end
    describe "more updates load properly" do
      subject { project.load_more_updates }
      it_returns "a collection", Kickscraper::Update
    end
  end

jamlen avatar Dec 31 '13 12:12 jamlen

That's a valid point @jamlen - I'll see about airlifting the update logic from client to project. I remember thinking about where to put the code initially, and now that you ask I can't recall a good reason for putting it on the client.

ghost avatar Dec 31 '13 17:12 ghost

Hey @ajkerrigan, a bunch of the code base has changed since you originally submitted this update... Would you like to check it out and see if your new changes still work?

I think we can pull this in, especially if you move the new methods to project instead of client...

benrugg avatar Feb 22 '14 20:02 benrugg

I won't be able to devote any time to this until at least next week, but I'd like to have a look and see what if anything can be salvaged. It won't meet my original need (crawling public and private updates for a user's backed projects), but I do think there's still some value in the pure public approach.

I agree that the methods make more sense on project. I'm struggling to remember why the heck I put them on client to begin with!

ghost avatar Feb 25 '14 19:02 ghost

Cool, thanks for checking it out again. I haven't done any work with pulling in project updates, but I'd love to see what's possible. (There are still both public and private api calls, so maybe you can do both for the updates).

benrugg avatar Feb 25 '14 19:02 benrugg