Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flesh out handling of Updates #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Flesh out handling of Updates #13

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 19, 2013

  • 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

Provide sequence number, title and body members.
Add methods to check for the presence of "more updates" and load them
if possible. Mirror the "more projects" functionality for the sake
of consistency.
@ghost
Copy link
Author

ghost commented Dec 19, 2013

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

@jamlen
Copy link
Collaborator

jamlen commented Dec 19, 2013

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 ?

@ghost
Copy link
Author

ghost commented Dec 19, 2013

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

@markolson
Copy link
Owner

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 :)

@benrugg
Copy link
Collaborator

benrugg commented Dec 19, 2013

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

- Add an update spec to test operations that apply to individual updates
- Add tests to the client spec for higher level operations that touch
  updates in bulk
@ghost
Copy link
Author

ghost commented Dec 24, 2013

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.

@benrugg
Copy link
Collaborator

benrugg commented Dec 28, 2013

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!

end

it "throws an error when accessing updates without a valid project loaded" do
subject { client.find_project TEST_PROJECT_ID }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, just looking at this right now. I'm wondering if this test is actually passing for the wrong reason. If TEST_PROJECT_ID is a valid project, why is subject nil on the next line?

Maybe the subject should be in a context block, and it should search for an invalid project id?

@benrugg
Copy link
Collaborator

benrugg commented Dec 30, 2013

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...

@ghost
Copy link
Author

ghost commented Dec 30, 2013

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

@benrugg
Copy link
Collaborator

benrugg commented Dec 31, 2013

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!)

@jamlen
Copy link
Collaborator

jamlen commented Dec 31, 2013

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

@ghost
Copy link
Author

ghost commented Dec 31, 2013

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.

@benrugg
Copy link
Collaborator

benrugg commented Feb 22, 2014

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...

@ghost
Copy link
Author

ghost commented Feb 25, 2014

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!

@benrugg
Copy link
Collaborator

benrugg commented Feb 25, 2014

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants